Add a gitignore
[p5sagit/App-FatPacker.git] / lib / App / FatPacker.pm
index b0dc9c9..453f3bc 100644 (file)
@@ -10,10 +10,10 @@ use File::Spec::Functions qw(
   catdir splitpath splitdir catpath rel2abs abs2rel
 );
 use File::Copy qw(copy);
-use File::Path qw(make_path remove_tree);
+use File::Path qw(mkpath rmtree);
 use B qw(perlstring);
 
-our $VERSION = '0.009001'; # 0.9.1
+our $VERSION = '0.009006'; # 0.9.6
 
 $VERSION = eval $VERSION;
 
@@ -47,7 +47,7 @@ sub new { bless({}, $_[0]) }
 sub run_script {
   my ($self, $args) = @_;
   my @args = $args ? @$args : @ARGV;
-  (my $cmd = shift @args) =~ s/-/_/g;
+  (my $cmd = shift @args || 'help') =~ s/-/_/g;
   if (my $meth = $self->can("script_command_${cmd}")) {
     $self->$meth(\@args);
   } else {
@@ -55,6 +55,10 @@ sub run_script {
   }
 }
 
+sub script_command_help {
+  print "Try `perldoc fatpack` for how to use me\n";
+}
+
 sub script_command_trace {
   my ($self, $args) = @_;
   
@@ -115,8 +119,8 @@ sub script_command_tree {
 
 sub packlists_to_tree {
   my ($self, $where, $packlists) = @_;
-  remove_tree $where;
-  make_path $where;
+  rmtree $where;
+  mkpath $where;
   foreach my $pl (@$packlists) {
     my ($vol, $dirs, $file) = splitpath $pl;
     my @dir_parts = splitdir $dirs;
@@ -135,7 +139,7 @@ sub packlists_to_tree {
       next unless substr($source,0,length $pack_base) eq $pack_base;
       my $target = rel2abs( abs2rel($source, $pack_base), $where );
       my $target_dir = catpath((splitpath $target)[0,1]);
-      make_path $target_dir;
+      mkpath $target_dir;
       copy $source => $target;
     }
   }
@@ -167,7 +171,8 @@ sub script_command_file {
 
     unshift @INC, sub {
       if (my $fat = $fatpacked{$_[1]}) {
-        open my $fh, '<', \$fat;
+        open my $fh, '<', \$fat
+          or die "FatPacker error loading $_[1] (could be a perl installation issue?)";
         return $fh;
       }
       return
@@ -178,7 +183,7 @@ sub script_command_file {
   my @segments = map {
     (my $stub = $_) =~ s/\.pm$//;
     my $name = uc join '_', split '/', $stub;
-    my $data = $files{$_}; $data =~ s/^/  /mg;
+    my $data = $files{$_}; $data =~ s/^/  /mg; $data =~ s/(?<!\n)\z/\n/;
     '$fatpacked{'.perlstring($_).qq!} = <<'${name}';\n!
     .qq!${data}${name}\n!;
   } sort keys %files;
@@ -192,8 +197,8 @@ App::FatPacker - pack your dependencies onto your script file
 =head1 SYNOPSIS
 
   $ fatpack trace myscript.pl
-  $ fatpack packlists-for `cat factpacker.trace` >packlists
-  $ fatpack tree fatlib `cat packlists`
+  $ fatpack packlists-for `cat fatpacker.trace` >packlists
+  $ fatpack tree `cat packlists`
   $ (fatpack file; cat myscript.pl) >myscript.packed.pl
 
 See the documentation for the L<fatpack> script itself for more information.