Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Removing unused Perl modules

by bliako (Monsignor)
on Apr 22, 2021 at 07:33 UTC ( [id://11131582]=note: print w/replies, xml ) Need Help??


in reply to Removing unused Perl modules

Module::Used, Module::ScanDeps, Module::Extract::Use et al., Devel::TraceUse can all be useful in listing what modules you instructed perl to use (as opposed to what modules are "usefully used" which is what you want).

I assume the difficult bit will be to find a way to remove each of these modules from source in order to see the effect on compilation (as you suggested in a comment below). Removing from source code (e.g. with regex) can be trickier than finding them. Because finding them usually involves reading the %INC and I am not sure whether removing from %INC will have any effect at all.

One thing that comes to my mind, totally untested, is: instead of removing a module from source code and run, just prepend a dir in @INC which will contain "fake" module files (with empty content, bar the boilerplate). For example:

mkdir -p fakemodules/Data echo "package Data::Dumper;1;" > fakemodules/Data/Dumper.pm # this will fail: perl -Ifakemodules -MData::Dumper -e'print Data::Dumper::Dumper([1])' a=$? # this succeeds: perl -MData::Dumper -e'print Data::Dumper::Dumper([1])' b=$? if [ $a -ne 0 ] && [ $b -eq 0 ]; then echo "module is required"; fi

1 minute edit: I think choroba mentioned a similar technique for mocking modules and probably this is where I got it from

bw, bliako

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2024-04-19 06:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found