Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Apply a source filter to all modules to be loaded?

by saintmike (Vicar)
on Mar 05, 2007 at 18:17 UTC ( [id://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?

Replies are listed 'Best First'.
Re: Apply a source filter to all modules to be loaded?
by Corion (Patriarch) 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? (yes)
by tye (Sage) 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 chromatic (Archbishop) on Mar 05, 2007 at 19:22 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
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?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2024-04-20 00:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found