Die if open fails in @INC handler
[p5sagit/App-FatPacker.git] / lib / App / FatPacker.pm
index b0dc9c9..aa3caef 100644 (file)
@@ -13,7 +13,7 @@ use File::Copy qw(copy);
 use File::Path qw(make_path remove_tree);
 use B qw(perlstring);
 
-our $VERSION = '0.009001'; # 0.9.1
+our $VERSION = '0.009003'; # 0.9.3
 
 $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) = @_;
   
@@ -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.