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 ]

wickline (135)

wickline
  (email not shown publicly)

Journal of wickline (135)

Wednesday July 10, 2002
09:03 AM

dump of module version information

[ #6252 ]
mako132 was looking for a way to get version info for
each module use'd by his script.

    http://use.perl.org/~mako132/journal/6244

I replied with a ~20 line END block which should do the
trick. I thought I might find the code handy myself one
day, so I thought I'd stash it in my journal as well for
ease of finding. ((code at end of journal entry))

Maybe that's a use for this journal... post odd bits of
code that don't have any associated project, invite any
readers to critique/improve/ridicule said code, look at
code years in the future when I can better do the same
to it.

-matt
(still deciding what to do with this journal thing)

END { no strict 'refs';
    for my $k ( sort keys %INC ) {
        ( my $module = $k ) =~ s{[:/\\]}{::}g;
        $module =~ s{\.pm$}{};
        my $version = ${"${module}::VERSION"};
        if ( defined $version ) {
            $version = "\$${module}::VERSION = $version\n";
        } else { # maybe they didn't use ALLCAPS
            my @found = (
                map { defined ${"${module}::$_"}
                     ? qq(\$${module}::$_ = ${"${module}::$_"}) : ()
                }
                grep { m/^version$/i }
                keys %{"${module}::"}
            );
            $version = !@found
                ? "($module  version number not found)\n"
                : join( "\n", @found );
        }
        # if you want, print this to a log file instead:
        print "$version $module  loaded from  $INC{$k}\n\n";
    }
}
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.
  • You can use $module->VERSION instead of ${"${module}::VERSION"};. And yes, it handles the case when package uses lowercase name of version variable.
    --

    Ilya Martynov (http://martynov.org/ [martynov.org])

    • That's handy to know :) ...and that makes things even tidier...
      (code below not yet tested...could have typos, etc)

      END {
          for my $k ( sort keys %INC ) {
              ( my $module = $k ) =~ s{[:/\\]}{::}g;
              $module =~ s{\.pm$}{};
              my $version = $module->VERSION;
              $version = defined $version
                  ? "\$${module}::VERSION = $version\n";