Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Ovid (2709)

Ovid
  (email not shown publicly)
http://publius-ovidius.livejournal.com/
AOL IM: ovidperl (Add Buddy, Send Message)

Stuff with the Perl Foundation. A couple of patches in the Perl core. A few CPAN modules. That about sums it up.

Journal of Ovid (2709)

Monday February 20, 2006
05:56 PM

What's loaded?

[ #28749 ]

Trying to debug a weird JSON error at work, where my boss gets a test failure that I don't, I've finally resorted to writing a tiny test module which dumps out the versions of all loaded modules:

package Loaded;

use strict;
use warnings;
use Module::Info;

sub versions {
    my @modules;
    my $max = 0;
    foreach my $module (sort keys %INC) {
        $module =~ s/\.pm$//;
        $module =~ s/\//::/g;
        next if $module =~ /^::/;
        next if __PACKAGE__ eq $module;
        if (length $module > $max) {
            $max = length $module;
        }
        my $mod = Module::Info->new_from_loaded($module);
        push @modules => [ $module, $mod ? $mod->version : 'Could not load' ];
    }
    @modules = sort { $a->[0] cmp $b->[0] } @modules;
    $max += 2;
    no warnings 'uninitialized';
    return join "\n", map { sprintf "%-${max}s %s", @$_ } @modules;
}

1;

And running it on itself:

  perl -MLoaded -e 'print Loaded->versions'
  AutoLoader           5.60
  Carp                 1.04
  Config
  DynaLoader           1.05
  Exporter             5.58
  File::Spec           3.14
  File::Spec::Unix     1.5
  Module::Info         0.290
  strict               1.03
  vars                 1.01
  version              0.49
  version::vxs         0.49
  warnings             1.03
  warnings::register   1.00

I was sure there would already be something like this on the CPAN. There is, right? What did I miss? (Devel::Loaded doesn't give me version numbers)

Using this in our code base shows 315 modules as loaded. Yikes!

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • > Using this in our code base shows 315 modules as loaded. Yikes!

    Think of all that functionality you didn't have to write, and how much useful functionality you can focus on because you're using these 315 modules. It's a plus, not a minus!

    If you're looking for a more useful way to present this information, you might want to whip up some CPAN cross-indexing magic to roll up the different class versions into distributions -- for instance, both File::Spec and File::Spec::Unix may be from the File::Spec

    • The 315 modules is a plus if you can control the environment. If you have a large package that you want to distribute, the more dependencies you have, the more problems you have in making something easy to install. Witness the Bricolage package. Many folks have had a heck of a time trying to install it because of all of those dependencies. Plus, when some dependencies aren't even from the CPAN, the problem becomes even worse.

      • It's a typical trade-off. Since installation is the only place this is a problem I think we should focus on that instead of trying to get rid of dependencies, similar to how the Krang folks did. (Not that you say we should get rid of dependencies, other folks do.) Creating friendly installations is pretty low on most developers' todo lists though (me included).