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

in each of my 258 perl modules i have a line like the follwing, corresponding to the current CVS revision:

our $CVS_REVISION = q!$Id: Action.pm,v 1.62 02/4/4 03:16:10 matt $!;

i'm trying to write a debugging routine which iterates over the keys of %INC (ie: to get the list of currently loaded modules), looking for the existence of this very $CVS_REVISION variable. I have been trying to use symbolic references (such as the code below) to achieve this, so far unsuccessfully. can anyone correct me?

{ no strict; local $^W = undef; my @versions = (); foreach my $class ( sort keys %INC ) { $class =~ s/\.pm$// or next; $class =~ s/\//::/g; my $version = ${"$class\::CVS_VERSION"} || next; push @versions, "$class -> $version"; } }

cheers, matt

Replies are listed 'Best First'.
Re: 'reflection', aka traversing symbol tables
by Zaxo (Archbishop) on Apr 06, 2002 at 07:48 UTC

    You're applying your matches to the names, not the files. Keep strict and warnings, here's a fairly cheesy approach:

    my $cvs_match = qr/whatever/; for (keys %INC) { push @versions, ($foo = `perldoc -m $_`) =~ /$cvs_match/; }
    Sorry that's not the whole job, but it's an outline.

    After Compline,
    Zaxo

      thanks for your reply. i should have included some context info. what i want to do is to be able to print the values of each module's $CVS_REVISION variable at the time that the source was initially parsed by Perl (which may be a different value than when this function is called). The intent is that i'd like to know what CVS versions of each module are being run in the currently executing mod_perl application.

      cheers, matt
Re: 'reflection', aka traversing symbol tables
by rjray (Chaplain) on Apr 06, 2002 at 08:47 UTC

    I would suggest having a look at the code in the Apache::Status module, which comes with mod_perl. It does a lot of stuff similar to this, and you're certain to find a few pieces of code that are useful to lift and adapt to your own needs.

    --rjray

ITYM
by Fletch (Bishop) on Apr 06, 2002 at 13:40 UTC
    my $version = ${"${class}::CVS_VERSION"} || next;

    That's a bit more standard, and it's clearer what you mean ( what's in $class follwed by "::CVS_VERSION" rather than $class::CVS_VERSION) than just backwhacking the colon.

Re: 'reflection', aka traversing symbol tables
by Anonymous Monk on Apr 06, 2002 at 21:46 UTC
    You're going to kick yourself :-)

    You said you're looking for values of $CVS_REVISION, but your code looks for values of $CVS_VERSION.