Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: How to keep track of INC hash?

by grinder (Bishop)
on Jul 15, 2008 at 05:27 UTC ( #697638=note: print w/replies, xml ) Need Help??


in reply to How to keep track of INC hash?

What is preventing you from installing a handler in @INC?

perl -le 'BEGIN{unshift @INC, sub {print $_[1]}} use CGI; # ... produces CGI.pm Carp.pm Exporter.pm CGI/Util.pm strict.pm vars.pm warnings/register.pm warnings.pm constant.pm overload.pm

It is then a simple matter of programming to figure out if your module is the one doing the loading. Or maybe not, if that's why you're asking the question. Is there something that rules out this approach?

• another intruder with the mooring in the heart of the Perl

Replies are listed 'Best First'.
Re^2: How to keep track of INC hash?
by massa (Hermit) on Jul 15, 2008 at 10:32 UTC
    Worked for me, too... I did:
    $ perl -e ' BEGIN { open my $f, "|sort>/tmp/uses.txt"; unshift @INC, sub { push @_, caller; print $f "module $_[2] uses $_[1]\n" } } do "bin/ponto" '
    where bin/ponto is the name of some script of mine, and I got the following in /tmp/uses.txt:
    module base uses vars.pm module Carp uses Exporter.pm module Compress::Zlib uses Compress/Raw/Zlib.pm module Compress::Zlib uses IO/Compress/Base/Common.pm
    ...
    module main uses bin/ponto module main uses Date/Manip.pm module main uses locale.pm module main uses open.pm module main uses strict.pm module main uses utf8.pm module main uses warnings.pm module main uses WWW/Mechanize.pm module main uses YAML/Syck.pm
    ...
    []s, HTH, Massa
Re^2: How to keep track of INC hash?
by jacques (Priest) on Jul 15, 2008 at 19:08 UTC
    ++ Your response answered my question as posed. Upon further reflection, I realized that what I really want is to prevent my module from making additions to INC in the first place. Is there a way to do that? Basically what I want to find out is the contents of the INC hash from a script that uses my module (but my module's dependencies should not be included in that data, unless those dependencies were used elsewhere in the program). Perhaps I could delete those particular additions to INC in an END block?
      I really want is to prevent my module from making additions to INC in the first place

      In other words, you don't want your module to load additional packages? In that case, return undef from your filter. See require for more information (I think this is the crux of matter in the wisdom you seek).

      • another intruder with the mooring in the heart of the Perl

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://697638]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2022-05-22 23:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (81 votes). Check out past polls.

    Notices?