App-Implode

 view release on metacpan or  search on metacpan

bin/implode  view on Meta::CPAN

  $exploder =~ s!^sub.*\@_;!BEGIN{my \$id='$id';!s;
  $exploder =~ s!^\s+!!mg;
  $exploder =~ s!\n!!g;

  open my $OUT, '>', $self->{out} or die "Could not write $self->{out}: $!\n";
  warn sprintf "Generating $self->{out} with embedded bzip archive...\n" if $self->verbose;
  print $OUT $script =~ s/^(#!.+?[\r\n]+)//m ? $1 : "#!/usr/bin/perl\n";
  print $OUT $exploder, "\n", $script, "\n__END__\n";
  $self->tarball->write(IO::Compress::Bzip2->new($OUT), COMPRESS_GZIP);
  close $OUT;
  chmod 0755, $self->{out};
  warn sprintf "$self->{out} is generated.\n" if $self->verbose;
}

sub chdir {
  my $self = shift;
  my $guard = bless [abs_path], ref($self);
  chdir $_[0] or die "chdir $_[0]: $!";
  $guard;
}

bin/implode  view on Meta::CPAN

sub slurp {
  my ($self, $file) = @_;
  open my $FH, '<', $file or die "Could not read $file: $!\n";
  local $/;
  readline $FH;
}

sub tarball {
  my $self  = shift;
  my $chdir = $self->chdir($self->tmpdir);
  my $chmod = sub { -f and chmod 0600 | (0777 & (stat _)[2]), $_ };
  my $files = sub { @_ > 1 and File::Find::find({no_chdir => 1, wanted => shift}, @_) };
  my $tar   = Archive::Tar->new;

  $files->(
    sub {
      return unless $chmod->();
      warn sprintf "Add @{[catfile $self->{tmpdir}, $_]}\n" if $self->verbose;
      $tar->add_files($_);
    },
    grep {-d} qw( bin lib )
  );

  undef $chdir;
  $files->(
    sub {
      return unless $chmod->() and s!lib!lib/perl5!;
      warn sprintf "Add $_\n" if $self->verbose;
      $tar->add_data($_, $self->slurp($File::Find::name));
    },
    grep {-d} qw( lib )
  );

  return $tar;
}

sub run {



( run in 0.396 second using v1.01-cache-2.11-cpan-496ff517765 )