Sub-refs in @INC screwing with your modules
Uri Guttman
uri at stemsystems.com
Wed Aug 5 21:32:39 BST 2009
>>>>> "DC" == David Cantrell <david at cantrell.org.uk> writes:
DC> As part of an Evil Plan, I am putting a sub-ref into @INC that will
DC> screw around with modules as they're loaded. Or at least, I'm trying
DC> to. I can't seem to get this to work:
DC> perl -MIO::Scalar -e '
DC> unshift @INC, sub {
DC> print q{wibble};
DC> return IO::Scalar->new(\q{print q{wobble}})
DC> };
DC> eval "use foo"
DC> '
DC> which *should*, if I've RTFM correctly, print "wibblewobble". But the
DC> wobble never appears. What am I doing wrong?
this works:
perl -le 'open my $fh, q{<}, \q{print q{bar}}; unshift @INC, sub {print q{foo}; $fh }; require baz'
foo
bar
i tried putting the open inside the sub and i get this error:
perl -le 'unshift @INC, sub {print q{foo}; open my $fh, q{<}, \q{bar}; $fh }; require bar'
foo
foo
Recursive call to Perl_load_module in PerlIO_find_layer at -e line 1.
BEGIN failed--compilation aborted.
why would it recurse on the sub in @INC? it prints foo twice which shows
that.
uri
--
Uri Guttman ------ uri at stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Free Perl Training --- http://perlhunter.com/college.html ---------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
More information about the london.pm
mailing list