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

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

Is there a standard module or regex out there to search a file system and list all modules that are actually being used?

We're preparing for a perl upgrade, and I want to avoid having to re-install modules that we no longer use. For example, we currently use DCE for authentication/authorization, so we have the DCE module. But we are moving off DCE, so we'll never need that module again.

I started writing a simple script to look for 'use', 'require', 'do', etc. but there are enough permutations that it started to seem non-trivial. There are other tricky bits like DBI and the RootClass option that is like a use, or Class::DBI with the inflate option that can indicate a module to use.

Anyone do this already?

Update: I'm starting to focus my problem based on the comments thus far.

  1. I want to try to do this without running the actual code. Specifically, I'm going to run some script against our Perforce depot (version control repository) because I feel I can trust that if it's in a prod mode there, it's running somewhere in our environment. Plus I can run the script any time without involving a bunch of other support people.
  2. By default, this limits what I can look at. As mentioned in Re: How do I detect what modules are not being used? and other places, you can't detect modules when the module or method names are generated dynamically. I don't think we do this much.
  3. I'm only looking for CPAN modules used by programs, not necessarily in-house modules. The difference is our in-house modules are all supported and the support person should know if it's being used or not.

So I'm considering going ahead with what I started which is to work file-by-file and look for all the ways I know of to pull in a module (use, require, etc. see above). I'll create a test file that uses all of them and add test cases as they come up. I think I'll start with Module::Info as suggested below and just add cases to that.