Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

How do I check if imports are actually used?

by Gertjan (Initiate)
on Sep 16, 2013 at 08:56 UTC ( #1054253=perlquestion: print w/ replies, xml ) Need Help??
Gertjan has asked for the wisdom of the Perl Monks concerning the following question:

Hi!

We have a lot of smaller and larger Perl-scripts and applications. In the course of time, new functionality is added and old code gets refactored or removed. Often people forget to remove imported modules when they are no longer needed, partly because it can be hard to see if a module is actually used. This adds a lot of unnecessary dependencies to the software.

How do you guys check which imports are actually needed? Most of the times I find myself searching through the code for occurrences of the module, while checking CPAN to see which symbols are automatically imported. This however is a very cumbersome method, and prone to error.

Thanks!
Gertjan

Comment on How do I check if imports are actually used?
Re: How do I check if imports are actually used?
by Anonymous Monk on Sep 16, 2013 at 09:00 UTC
Re: How do I check if imports are actually used?
by LanX (Canon) on Sep 16, 2013 at 13:37 UTC
    2 possibilities come to mind

  • Use B::Xref to parse each source file potentially using your modules

  • extend deprecated functions to log the caller each time they are called.

    Attribute::Handlers could be used to build such wrappers.

    Update

  • you can also extend the importer() of your modules to check the importing files.

    Cheers Rolf

    ( addicted to the Perl Programming Language)

Re: How do I check if imports are actually used?
by Your Mother (Canon) on Sep 16, 2013 at 13:48 UTC

    There's also Hook::LexWrap. Not really recommending but I think it could be made to work (with quite a bit of coding).

      Maybe overkill.

      I think goto  &sub should already be caller transparent.

      And the OP doesn't need post hooks.

      Cheers Rolf

      ( addicted to the Perl Programming Language)

Re: How do I check if imports are actually used? (script)
by tye (Cardinal) on Sep 16, 2013 at 16:28 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1054253]
Approved by marto
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (2)
As of 2014-09-22 02:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (177 votes), past polls