Re: [Parseperl-discuss] PPI to get package/versions
Brought to you by:
adamkennedy
From: Elliot S. <pe...@ga...> - 2010-03-11 03:35:33
|
On 3/10/10 6:13 PM, Todd Rinaldo wrote: > I want to use PPI to determine all packages and their $VERSION in a > given pm file. I've determined how to get the list of packages in the > file, but not the version. How can I do this? The only authoritative way of doing this is to load the module and check it at runtime. (Of course, determining which namespaces got twiddled in the process is difficult. You might want to look at http://search.cpan.org/dist/Module-Extract-VERSION/. If you want to do it yourself via PPI, I would probably set up a state machine that tracked what the current package is and when a $VERSION assignment is found, save it off in a stash of some sort. Alternatively, there's http://perlcritic.tigris.org/source/browse/perlcritic/trunk/distributions/PPIx-Utilities/lib/PPIx/Utilities/Node.pm?revision=3777&view=markup. You could use it to split your module up into namespaces and then look for $VERSION assignments in that. (I haven't released this yet due to wanting to move some code from Perl::Critic into the distribution first, but I'm still debating how to do it.) |