Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Code Reviews -- List Identifiers

by QM (Parson)
on Nov 22, 2013 at 12:10 UTC ( #1063926=perlquestion: print w/replies, xml ) Need Help??
QM has asked for the wisdom of the Perl Monks concerning the following question:

Is there a tool/module/script that will list all (or most) identifiers in a Perl program?

We're trying to enforce a rule for code reviews such that identifiers are meaningful, and things such as $bsefs are easy to spot. Sure, spell checkers can weed out some examples. But I came across one today that was el_in_g1, which passed my spell checker, due to underbars and single characters.

Quantum Mechanics: The dreams stuff is made of

Replies are listed 'Best First'.
Re: Code Reviews -- List Identifiers
by LanX (Bishop) on Nov 22, 2013 at 14:12 UTC
    I think parsing the html output of perltidy is easy ... Just grep the content of the span-tags with css-classes you want.

    PPI is state of the art though I have trouble motivating me to dive into the details...

    But if you want to enforce coding styles anyway, you should consider designing appropriate Perl::Critic rules.


    And of course B::Xref or tools like ctags could be of help.

    Cheers Rolf

    ( addicted to the Perl Programming Language)

Re: Code Reviews -- List Identifiers
by arkturuz (Curate) on Nov 22, 2013 at 13:00 UTC
    There are many options. If you would like to script something of your own, you could use PPI for custom source code analysis. There's also Perl::Critic which is mostly used for this kind of things with its set of predefined rules.

      Here's a quick PPI example:

      use v5.12; use PPI; my $perl = PPI::Document::->new(do { local $/ = <DATA>; \$/ }); say $_ for @{ $perl->find('PPI::Token::Symbol') }; __DATA__ # Some sample code to analyse my $foo = 1; my @bar = (2, 3); say $bar[0];

      The output includes a variable called $bar which doesn't really exist :-( But that shouldn't be a problem for the OP's use case.

      use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name
Re: Code Reviews -- List Identifiers
by hdb (Monsignor) on Nov 22, 2013 at 13:06 UTC

    Something simple like this could be a start (with filenames given on the command line):

    use strict; use warnings; my %identifiers; undef $/; undef @identifiers{ /((?:sub\s+|[\$@%])[a-zA-Z_][a-zA-Z_0-9]*)/g } whi +le <>; print join "\n", keys %identifiers;

    but there are more things to find, like module names etc.

Re: Code Reviews -- List Identifiers
by jellisii2 (Hermit) on Nov 22, 2013 at 12:53 UTC
    Komodo IDE has code intelligence baked in and will give you this information on the GUI. I'm unclear if it'll give it to you in another fashion that easier to distribute, though.

Re: Code Reviews -- List Identifiers
by RMGir (Prior) on Nov 22, 2013 at 13:26 UTC
    I wonder whether you could extend B::Lint to do this?

    It's not clear from the perldoc on the 5.12.2 perl I have handy, but it does support some kind of plugins.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1063926]
Front-paged by Corion
[ambrus]: Corion: exactly. by pre-forking you avoid that, because you spawn processes from a smaller process that never uses threads and is kept only to spawn things
[ambrus]: (and to wait for the spawned stuff)

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (10)
As of 2017-10-19 15:05 GMT
Find Nodes?
    Voting Booth?
    My fridge is mostly full of:

    Results (255 votes). Check out past polls.