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!
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 distribution version 1.03.
Re:315 modules and counting!
Ovid on 2006-02-21T08:26:30
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.
Re:315 modules and counting!
lachoy on 2006-02-21T16:10:25
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).