Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Apply a source filter to all modules to be loaded?

by saintmike (Vicar)
on Mar 05, 2007 at 18:17 UTC ( #603253=perlquestion: print w/ replies, xml ) Need Help??
saintmike has asked for the wisdom of the Perl Monks concerning the following question:

Is there a way to hook into the module loading process, so that a source filter gets applied to all modules loaded afterwards?

Some thing like:

BEGIN { # ... some magic } use Foo::Bar; # Source filter gets applied # when it's loaded.
Or is this crazy talk?

Comment on Apply a source filter to all modules to be loaded?
Download Code
Re: Apply a source filter to all modules to be loaded? (yes)
by tye (Cardinal) on Mar 05, 2007 at 18:39 UTC
    Is there a way to hook into the module loading process

    Yes. unshift a code ref onto @INC.

    so that a source filter gets applied to all modules loaded afterwards [....] Or is this crazy talk?

    Yes, pretty much. (Some others might care what the original problem you are trying to solve is.)

    - tye        

Re: Apply a source filter to all modules to be loaded?
by Corion (Pope) on Mar 05, 2007 at 18:44 UTC

    This is crazy talk, but that's not stopping Perl from having it, see require:

    sub my_own_loader { my ($self,$file) = @_; open my $fh, "<", "my/private/dir/$file" or return; $fh }; BEGIN { unshift @INC, \&my_own_loader; }; use Foo::Bar; use The::Net;

    You might also want to look at Filter::Simple, but please realize that source filtering isn't a sane practice :)

Re: Apply a source filter to all modules to be loaded?
by chromatic (Archbishop) on Mar 05, 2007 at 19:22 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://603253]
Approved by Old_Gray_Bear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (6)
As of 2014-07-13 18:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (251 votes), past polls