use strict;
use autodie;
use IO::Compress::Gzip qw(gzip $GzipError);
use File::Slurp;
use File::Basename;
#Ref: How to use Gzip/Gunzip
#http://blog.livedoor.jp/moya_pro/archives/21566288.html
unless ($ARGV[0]) {
die "usage:". basename($0) ." inputfilename [>outputfilename]";
}
my $targetCode = read_file( $ARGV[0], { binmode => ':raw' } ) ;
my $buf;
gzip \$targetCode => \$buf or die "$GzipError";
print "#This file is generated by ". basename($0) . ".\n";
print "#Do not modify this file with a text editor.(or _DATA_ part will be broken.)\n";
print <<'EOD';
use IO::Uncompress::Gunzip qw(gunzip $GunzipError);
my $code;
my $zipcode = join('',map{$_}<DATA>);
gunzip \$zipcode => \$code or die "$GunzipError";
eval $code;
if ($@) {die $@, "\n";}
__DATA__
EOD
binmode(STDOUT);
print $buf;