From: Rafael Garcia-Suarez Date: Sat, 29 Sep 2001 23:54:48 +0000 (+0200) Subject: additional docs and tests X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=9ae8cd5b44680cc8af3d7ecc507f22e5e2031731;p=p5sagit%2Fp5-mst-13.2.git additional docs and tests Message-ID: <20010929235448.A5017@rafael> p4raw-id: //depot/perl@12275 --- diff --git a/pod/perlfunc.pod b/pod/perlfunc.pod index 69e44ff..86a09ba 100644 --- a/pod/perlfunc.pod +++ b/pod/perlfunc.pod @@ -3882,6 +3882,9 @@ C
.) 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. + For a yet-more-powerful import facility, see L and L. =item reset EXPR diff --git a/pod/perlvar.pod b/pod/perlvar.pod index e61e8ed..6f9bd8d 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 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 3ccea1a..bd66628 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;