http://qs1969.pair.com?node_id=734753

brycen has asked for the wisdom of the Perl Monks concerning the following question:

I'm working with a large legacy system with an install script that pulls in close to 200 perl modules. Now at least 25% and probably 50% of those are never used.

I can start by greping for all the "use" lines, then diff to see what I can trim. But is there a way to do better? To determine which pm's are in are "use'ed without actually getting used?

The goal here is to convert as many CPAN modules into supported Debian packages, by the way. And sometimes it's awkward to start with a use statement and end up with the proper Debian name.

Replies are listed 'Best First'.
Re: Identify and trim unused undeeded perl modules
by kyle (Abbot) on Jan 07, 2009 at 22:48 UTC

    Maybe you could run the install script under Devel::Cover and see which code is actually used. You'd have to be careful, however, that you don't cut out code that gets used in some case that you're not exercising.

Re: Identify and trim unused undeeded perl modules
by CountZero (Bishop) on Jan 07, 2009 at 23:02 UTC
    Devel::Dependencies might be of assistance here.

    According to the docs it "uses a BEGIN and a CHECK block to find the changes in %INC".

    Of course, if a module is use-d but never actually used, it will still show up in %INC.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James