perldependenciesmodulecpan

How do I find the module dependencies of my Perl script?


I want another developer to run a Perl script I have written. The script uses many CPAN modules that have to be installed before the script can be run. Is it possible to make the script (or the perl binary) to dump a list of all the missing modules? Perl prints out the missing modules’ names when I attempt to run the script, but this is verbose and does not list all the missing modules at once. I’d like to do something like:

$ cpan -i `said-script --list-deps`

Or even:

$ list-deps said-script > required-modules # on my machine
$ cpan -i `cat required-modules` # on his machine

Is there a simple way to do it? This is not a show stopper, but I would like to make the other developer’s life easier. (The required modules are sprinkled across several files, so that it’s not easy for me to make the list by hand without missing anything. I know about PAR, but it seems a bit too complicated for what I want.)


Update: Thanks, Manni, that will do. I did not know about %INC, I only knew about @INC. I settled with something like this:

print join("\n", map { s|/|::|g; s|\.pm$||; $_ } keys %INC);

Which prints out:

Moose::Meta::TypeConstraint::Registry
Moose::Meta::Role::Application::ToClass
Class::C3
List::Util
Imager::Color
…

Looks like this will work.


Solution

  • You could dump %INC at the end of your script. It will contain all used and required modules. But of course, this will only be helpful if you don't require modules conditionally (require Foo if $bar).