develooper Front page | perl.perl5.porters | Postings from September 2001

[PATCH perlvar, perlfunc, inccode.t] additional docs and tests

Thread Next
From:
Rafael Garcia-Suarez
Date:
September 29, 2001 14:50
Subject:
[PATCH perlvar, perlfunc, inccode.t] additional docs and tests
Message ID:
20010929235448.A5017@rafael
Some more docs, to underline some more DWIMery ; and the tests that go with it.


--- pod/perlvar.pod.orig	Mon Sep 24 00:15:13 2001
+++ pod/perlvar.pod	Sat Sep 29 22:32:01 2001
@@ -1158,7 +1158,9 @@
 
 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
 
--- pod/perlfunc.pod.orig	Sun Sep 23 19:35:05 2001
+++ pod/perlfunc.pod	Sat Sep 29 22:31:11 2001
@@ -3882,6 +3882,9 @@
     # 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
--- t/op/inccode.t.orig	Tue Sep 25 17:32:37 2001
+++ t/op/inccode.t	Sat Sep 29 22:46:24 2001
@@ -10,7 +10,7 @@
 use File::Spec;
 
 require "test.pl";
-plan(tests => 39);
+plan(tests => 43);
 
 my @tempfiles = ();
 
@@ -132,5 +132,23 @@
 is( ref $INC{'Quux2.pm'}, 'FooLoader',
 				   '  key is an object in %INC' );
 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;

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About