Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Code Reviews -- List Identifiers

by QM (Vicar)
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.

-QM
--
Quantum Mechanics: The dreams stuff is made of

Comment on Code Reviews -- List Identifiers
Select or Download Code
Re: Code Reviews -- List Identifiers
by jellisii2 (Friar) 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 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 (Parson) 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 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.


    Mike
Re: Code Reviews -- List Identifiers
by LanX (Canon) 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.

    update

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

    Cheers Rolf

    ( addicted to the Perl Programming Language)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1063926]
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (11)
As of 2014-08-22 20:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (164 votes), past polls