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

Esteemed monks,

I have a question about module dependencies in Perl. I was thinking about various modules available on CPAN, and occasionally I see "pure Perl" modules, e.g. HTTP::Server::Brick. Ostensibly, pure Perl modules have no dependencies that are not part of the core Perl distribution.

My question is this: is there a metric for measuring the "level of dependency" for a given module? (Or a script, for that matter...)

Example: "pure Perl" modules might be analogous to level zero. A module that depends only on other pure Perl modules could be a level one, and so on.

I was just curious if there is a way to measure, i.e. quantify, a module's dependency tree. I thought of this while I was saying, "Yes," to cpan asking me if I wanted to install prerequisites, then "yes" again to the prerequisites of the prerequisites, and so on. I'd like to see that list up front before installing everything.

Is there something out there than can help with this? I'd also like to measure the "levels of dependency" between a given module and the "pure Perl level" - if that makes sense.

Thanks in advance for your thoughts.

-MC

Replies are listed 'Best First'.
Re: "Levels of Dependency"?
by Corion (Patriarch) on Jul 23, 2007 at 08:06 UTC

    Conventionally, "pure Perl" means that a module relies only on other modules and no compiled C ("XS") portion. HTTP::Server::Brick relies on other non-core modules, as the Build.PL script shows:

    ... requires => { 'Module::Build' => 0, 'Test::More' => 0, 'version' => 0, 'HTTP::Daemon' => 0, 'HTTP::Status' => 0, 'LWP::MediaTypes' => 0, 'LWP' => 0, 'LWP::UserAgent' => 0, 'IO::Handle' => 0, }, ...

    It relies on Module::Build which will only be core in a future version of Perl, and LWP.

    The quest of building a prerequisite tree for modules is hard because of the nature of the Perl module build process. Traditionally, all prerequisites have been determined by Perl programs, be it Makefile.PL or Build.PL. There has been the trend of listing prerequisites in the META.yml file for more convenient inspection. If you want to build the dependency graph of modules, I suggest you install a local CPAN mirror via CPAN::Mini and extract all META.yml files from the distributions and build the tree from that.

    Update: Thinking a bit more about it, you can cut some corners by using Module::CoreList to immediately find the modules included in the Perl cores. This does not necessarily mean that a module in the Perl core does not live a dual life in the Perl core and on CPAN. And there is Module::ThirdParty which links in third party modules that do not live on CPAN but are (possibly) required by CPAN modules.

Re: "Levels of Dependency"?
by samtregar (Abbot) on Jul 23, 2007 at 17:37 UTC