This patch makes useful the info put in %INC when a file is
loaded via a hook. So, if several hooks are put in @INC, it's
possible to know which hook loaded which module.
Example :
push @INC, sub {
if ($_[1] eq 'Foo.pm') { return *DATA } else { return undef }
};
require Foo;
print "$INC{'Foo.pm'} - $INC[$#INC]\n";
__DATA__
package Foo; 1;
Output :
/loader/0x81095c8/Foo.pm - CODE(0x81095c8)
The addresses now match.
I also briefly documented this in perlvar/%INC.
I'll add tests for this, but the fact that the tests do not run
on perl+stdio annoys me. (Simply returning *DATA from the hook may be
a solution.)
--- pp_ctl.c.orig Mon Aug 27 18:20:23 2001
+++ pp_ctl.c Tue Aug 28 11:58:23 2001
@@ -3160,7 +3160,7 @@
}
Perl_sv_setpvf(aTHX_ namesv, "/loader/0x%"UVxf"/%s",
- PTR2UV(SvANY(loader)), name);
+ PTR2UV(SvRV(dirsv)), name);
tryname = SvPVX(namesv);
tryrsfp = 0;
--- pod/perlvar.pod.orig Sat Aug 25 17:39:13 2001
+++ pod/perlvar.pod Tue Aug 28 12:19:01 2001
@@ -1080,6 +1080,11 @@
operator uses this hash to determine whether a particular file has
already been included.
+If the file was loaded via a hook (see L<perlfunc/require> for a
+description of these hooks), a fake filename is inserted into %INC. It
+looks like F</loader/0x81095c8/Foo.pm>, where the hexadecimal number
+corresponds to the reference that was put in @INC.
+
=item %ENV
=item $ENV{expr}
Thread Next