Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: disabling unnecessary perl modules

by InfiniteSilence (Curate)
on May 29, 2014 at 22:24 UTC ( #1087888=note: print w/replies, xml ) Need Help??


in reply to disabling unnecessary perl modules

Hey, in the future can you not put an entire script in Perlmonks? Wait until someone asks you for a specific piece of code rather than dump the whole thing.

The answer to your question is going to be rather messy:

# cat foo.pl # ----------- #!/usr/bin/perl -w use strict; use CGI; use LWP::Simple; 1; strace perl foo.pl 2> foo.pl.strace perl -ne 'if(m/(\S+\.pm)/){print qq|$1\n|}' foo.pl.strace|sort|uniq|ca +t -n

Produces (in short):

... 149 stat64("/usr/lib/perl5/site_perl/5.10.0/LWP.pm 150 stat64("/usr/lib/perl5/site_perl/5.10.0/LWP/Protocol.pm 151 stat64("/usr/lib/perl5/site_perl/5.10.0/LWP/Simple.pm 152 stat64("/usr/lib/perl5/site_perl/5.10.0/LWP/UserAgent.pm 153 stat64("/usr/lib/perl5/site_perl/5.10.0/URI/Escape.pm 154 stat64("/usr/lib/perl5/site_perl/5.10.0/URI.pm 155 stat64("/usr/lib/perl5/vendor_perl/5.10.0/Encode/ConfigLocal +.pm 156 stat64("/usr/lib/perl5/vendor_perl/5.10.0/i586-linux-thread- +multi/Encode/ConfigLocal.pm 157 stat64("/usr/lib/perl5/vendor_perl/5.10.0/i586-linux-thread- +multi/Log/Agent.pm 158 stat64("/usr/lib/perl5/vendor_perl/5.10.0/Log/Agent.pm 159 stat64("/usr/lib/perl5/vendor_perl/Encode/ConfigLocal.pm 160 stat64("/usr/lib/perl5/vendor_perl/Log/Agent.pm 161 XSLoader.pm

So, for a script that does nothing interesting and only uses two modules Perl actually checks for the presence of 161 modules. Looking at %INC only shows 37 elements for the same script, so I'm inclined to think that strace is giving me the bigger picture. Figuring out which modules you can live without should be a chore. I think you can save yourself the headache and just put all of the modules a script needs in a PAR archive and reference that.

Celebrate Intellectual Diversity

Replies are listed 'Best First'.
Re^2: disabling unnecessary perl modules
by tobyink (Canon) on May 29, 2014 at 23:27 UTC

    The reason why strace is more verbose than %INC is that Perl has to stat a file to see whether it exists. So say you've got:

    BEGIN { @INC = qw( /tmp/lib1 /tmp/lib2/ /tmp/lib3 ); } use Foo::Bar;

    And /tmp/lib3/Foo/Bar.pm is the only module that exists, Perl still has to stat /tmp/lib1/Foo/Bar.pm and /tmp/lib2/Foo/Bar.pm first. Only one actual module is loaded though.

    (Actually Perl will also stat /tmp/lib1/Foo/Bar.pmc, /tmp/lib2/Foo/Bar.pmc, and /tmp/lib3/Foo/Bar.pmc too. This is due to a rarely used feature where Perl will try to load modules with .pmc extensions ahead of .pm. The intention is that you might write your code a Bar.pm and then "compile" it to Bar.pmc for deployment. I don't mean "compile" in the same sense that C is compiled; more like what Parse::RecDescent's Precompile method does.)

    use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name
Re^2: disabling unnecessary perl modules
by oiskuu (Hermit) on May 30, 2014 at 20:27 UTC

    Another method that might come handy, is to check access times.

    $ touch STAMP
    $ mount /usr -o remount,strictatime
    $ sh my-test-foo.sh
    $ find /usr -type f ! -anewer STAMP | xargs echo rm
    

Re^2: disabling unnecessary perl modules
by RonW (Parson) on May 30, 2014 at 16:31 UTC
    Your example is only looking at .pm files. Some modules also load shared libraries - usually either .so or .dll

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (None)
    As of 2022-01-26 05:48 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      In 2022, my preferred method to securely store passwords is:












      Results (69 votes). Check out past polls.

      Notices?