summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pod/perlfunc.pod3
-rw-r--r--pod/perlvar.pod4
-rw-r--r--t/op/inccode.t20
3 files changed, 25 insertions, 2 deletions
diff --git a/pod/perlfunc.pod b/pod/perlfunc.pod
index 69e44ffd01..86a09ba8dc 100644
--- a/pod/perlfunc.pod
+++ b/pod/perlfunc.pod
@@ -3882,6 +3882,9 @@ C<main>.) Here is a typical code layout:
# In the main program
push @INC, new Foo(...);
+Note that these hooks are also permitted to set the %INC entry
+corresponding to the files they have loaded. See L<perlvar/%INC>.
+
For a yet-more-powerful import facility, see L</use> and L<perlmod>.
=item reset EXPR
diff --git a/pod/perlvar.pod b/pod/perlvar.pod
index e61e8ed646..6f9bd8d3a6 100644
--- a/pod/perlvar.pod
+++ b/pod/perlvar.pod
@@ -1158,7 +1158,9 @@ already been included.
If the file was loaded via a hook (e.g. a subroutine reference, see
L<perlfunc/require> for a description of these hooks), this hook is
-inserted into %INC in place of a filename.
+by default inserted into %INC in place of a filename. Note, however,
+that the hook may have set the %INC entry by itself to provide some more
+specific info.
=item %ENV
diff --git a/t/op/inccode.t b/t/op/inccode.t
index 3ccea1a0a4..bd66628c0a 100644
--- a/t/op/inccode.t
+++ b/t/op/inccode.t
@@ -10,7 +10,7 @@ BEGIN {
use File::Spec;
require "test.pl";
-plan(tests => 39);
+plan(tests => 43);
my @tempfiles = ();
@@ -134,3 +134,21 @@ is( ref $INC{'Quux2.pm'}, 'FooLoader',
is( $INC{'Quux2.pm'}, $sref, ' key is correct in %INC' );
pop @INC;
+
+push @INC, sub {
+ my ($self, $filename) = @_;
+ if (substr($filename,0,4) eq 'Toto') {
+ $INC{$filename} = 'xyz';
+ return get_temp_fh($filename);
+ }
+ else {
+ return undef;
+ }
+};
+
+ok( eval { require Toto; 1 }, 'require() magic via anonymous code ref' );
+ok( exists $INC{'Toto.pm'}, ' %INC sees it' );
+ok( ! ref $INC{'Toto.pm'}, q/ key isn't a ref in %INC/ );
+is( $INC{'Toto.pm'}, 'xyz', ' key is correct in %INC' );
+
+pop @INC;