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

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";
                  : "($module  version number not found)\n";
              # if you want, print this to a log file instead:
              print "$version $module  loaded from  $INC{$k}\n\n";
          }
      }
      ... or maybe it needs to be defined and length instead of just defined. Guess I'll have to try it to see what gets returned when there is no version...
      -matt