additional docs and tests
authorRafael Garcia-Suarez <rgarciasuarez@gmail.com>
Sat, 29 Sep 2001 23:54:48 +0000 (01:54 +0200)
committerJarkko Hietaniemi <jhi@iki.fi>
Sun, 30 Sep 2001 00:11:21 +0000 (00:11 +0000)
Message-ID: <20010929235448.A5017@rafael>

p4raw-id: //depot/perl@12275

pod/perlfunc.pod
pod/perlvar.pod
t/op/inccode.t

index 69e44ff..86a09ba 100644 (file)
@@ -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
index e61e8ed..6f9bd8d 100644 (file)
@@ -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
 
index 3ccea1a..bd66628 100644 (file)
@@ -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;