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

Hello fellow monks,

I am building an online repository of help files (using pod2html) for various Perl modules that we have developed. I would really like to be able to include the current version of the module as part of the POD, so that it will appear in the help.

If I can't access the variable from within the POD, perhaps I could extend the POD parser to interpolate the $VERSION variable. I checked on CPAN to see if someone has already done this, but I didn't find anything.

Of course, I could just maintain the version number in 2 spots, but I'm looking to avoid the duplication if possible.

Help/comments/sugestions are much appreciated!
  • Comment on Can a module's POD access the module's variables?

Replies are listed 'Best First'.
Re: Can a module's POD access the module's variables?
by Perl Mouse (Chaplain) on Dec 09, 2005 at 22:41 UTC
    POD isn't executable code, so the answer is no.

    However, that doesn't mean you can't have a version number in your POD. I often use CVS to do my version control, and with CVS, you can tell it to stick in a version number. Something as simple as the following will do:

    =head1 VERSION $Revision: $
    When checking in, CVS will stick the current version number inside the tag.

    To get the version number inside a variable, I use something like:

    our ($VERSION) = q $Revision: $ =~ /[\d.]+/g;
    Perl --((8:>*
Re: Can a module's POD access the module's variables?
by xdg (Monsignor) on Dec 09, 2005 at 23:40 UTC

    The easiest thing is probably to filter the source file before feeding it to pod2html. Use Module::Info to extract the version, then either replace some keyword like __VERSION__ in the Pod, or insert a brand new version section in the Pod, then send it on to pod2html.

    -xdg

    Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Re: Can a module's POD access the module's variables?
by ptum (Priest) on Dec 09, 2005 at 22:44 UTC

    This is a little on the kludgy side, but one approach I take for $work POD is to post-parse and process (whew! A lot of 'P's!) the pod2html output. I have a little CGI script that does a real-time pod2html conversion (it is pretty fast) for whatever module a user picks out of a list and then edits the resulting HTML on the fly before presenting it. I tweak things like the title displayed and add in default text when the POD is incomplete or flawed.


    No good deed goes unpunished. -- (attributed to) Oscar Wilde
Re: Can a module's POD access the module's variables?
by tinita (Parson) on Dec 11, 2005 at 16:14 UTC
    i tried to do the same for HTML::Template::Compiled, and it worked:
    my $version_pod = <<'=cut'; =pod =head1 NAME HTML::Template::Compiled - Template System [...] =head1 VERSION our $VERSION = "0.57"; =cut # doesn't work with make tardist our $VERSION = ($version_pod =~ m/^our \$VERSION = "(\d+(?:\.\d+)+)"/m +) ? $1 : "0.01";
    but as you can see from the comment, if i package the thing up with make tardist, it fails. so i commented it out.

    my reason for this was to always have the version visible in the pod and up-to-date with the $VERSION variable (and not using the cvs revision). to address this, i wrote a test-script that compares the two strings, so i'm always safe when the testsuite succeeds.

      That's exactly what I was looking for!

      All of the solutions provided are interesting, but this one in particular is perfect for what we are trying to do.

      Thanks for the input everyone!