Sub-refs in @INC screwing with your modules

Randy J. Ray rjray at
Wed Aug 5 20:57:21 BST 2009

David Cantrell wrote:
> As part of an Evil Plan, I am putting a sub-ref into @INC that will
> screw around with modules as they're loaded.  Or at least, I'm trying
> to.  I can't seem to get this to work:
> perl -MIO::Scalar -e '
>     unshift @INC, sub {
>         print q{wibble};
>         return IO::Scalar->new(\q{print q{wobble}})
>     };
>     eval "use foo"
> '
> which *should*, if I've RTFM correctly, print "wibblewobble".  But the
> wobble never appears.  What am I doing wrong?

Does the IO::Scalar object appear as a proper typeglob to Perl? According to
"perldoc -f require", if the return value looks like a tied filehandle it gets

	"Note that this file handle must be
        a real file handle (strictly a typeglob, or reference to a
        typeglob, blessed or unblessed) - tied file handles will be
        ignored and return value processing will stop there."

Randy J. Ray      Sunnyvale, CA   rjray at

Silicon Valley Scale Modelers:

More information about the mailing list