From: Diab Jerius <djerius@cfa.harvard.edu>
Date: Fri, 15 Nov 2013 17:27:42 +0000 (-0500)
Subject: use an @INC object hook instead of a subref to provide info on the packed files
X-Git-Tag: v0.010000~10
X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=e7051d24e8b8cc6556d3e2fcdaf00a1348e4a791;p=p5sagit%2FApp-FatPacker.git

use an @INC object hook instead of a subref to provide info on the packed files

Perl allows an @INC hook to be an object.  Use this to provide a
method (files) returning the files which were packed.  This allows
other code (e.g. Module::Pluggable) to interoperate with
App::FatPacker in a standardized fashion.
---

diff --git a/lib/App/FatPacker.pm b/lib/App/FatPacker.pm
index 16b8cdd..24abeaf 100644
--- a/lib/App/FatPacker.pm
+++ b/lib/App/FatPacker.pm
@@ -268,24 +268,38 @@ sub fatpack_end {
   return stripspace <<'  END_END';
     s/^  //mg for values %fatpacked;
 
-    unshift @INC, sub {
-      if (my $fat = $fatpacked{$_[1]}) {
-        if ($] < 5.008) {
-          return sub {
-            return 0 unless length $fat;
-            $fat =~ s/^([^\n]*\n?)//;
-            $_ = $1;
-            return 1;
-          };
-        }
-        open my $fh, '<', \$fat
-          or die "FatPacker error loading $_[1] (could be a perl installation issue?)";
-        return $fh;
+
+    if ($] < 5.008) {
+       unshift @INC, sub {
+         if (my $fat = $fatpacked{$_[1]}) {
+           return sub {
+             return 0 unless length $fat;
+             $fat =~ s/^([^\n]*\n?)//;
+             $_ = $1;
+             return 1;
+           };
+         }
+         return;
       }
-      return
-    };
+    }
+
+    else {
+
+      my $class = "${\\%fatpacked}";
+      unshift @INC, bless \%fatpacked, $class;
+      *{"${class}::files"} = sub { keys %{$_[0]} };
+      *{"${class}::INC"} = sub {
+  	if (my $fat = $_[0]{$_[1]}) {
+          open my $fh, '<', \$fat
+            or die "FatPacker error loading $_[1] (could be a perl installation issue?)";
+          return $fh;
+        }
+        return;
+      };
+
+    }
 
-    } # END OF FATPACK CODE
+  } # END OF FATPACK CODE
   END_END
 }