Git Product home page Git Product logo

perl-metrics-simple's Introduction

NAME
    Perl::Metrics::Simple - Static analysis of Perl code. Counts complexity, packages, subs, lines, etc. of many files.

DESCRIPTION

    Perl::Metrics::Simple provides methods to run static
    analysis of one or many Perl files and obtain a few metrics: packages,
    subroutines, lines of code, and cyclomatic (mccabe) complexity of the
    subroutines and the "main" portion of the code.
    
    Perl::Metrics::Simple is far simpler that Perl::Metrics.

    Installs a script called countperl.

AUTHOR
        Matisse Enzer
        CPAN ID: MATISSE
        Eigenstate Consulting, LLC
        [email protected]
        http://www.eigenstate.net/

LICENSE AND COPYRIGHT
    This program is free software; you can redistribute it and/or modify it
    under the same terms as Perl itself.

    The full text of the license can be found in the LICENSE file included
    with this module.

SEE ALSO
    PPI
    Perl::Critic
    Perl::Metrics
    http://en.wikipedia.org/wiki/Cyclomatic_complexity

perl-metrics-simple's People

Contributors

matisse avatar mephinet avatar fschlich avatar jwrightecs avatar bsingr avatar polamjag avatar

Stargazers

Alexandre Espinosa Menor avatar M. Scott Ford avatar  avatar  avatar Sergiy Borodych avatar

Watchers

 avatar

perl-metrics-simple's Issues

_rewrite_moose_method_modifiers fails to parse method modifiers using double quotes (or qq)

when rewriting method modifiers,Perl::Metrics::Simple::Analysis::File attempts to use the PPI::Token::Quote literal method on the method name. This works for PPI::Token::Quote::Single and PPI::Token::Word, but not for PPI::Token::Quote::Double and PPI::Token::Quote::Interpolate which lack a 'literal' method. Replacing literal with string + unescape seems to work, but would require checking that ->string is a valid word / subname

$ cat test.pl                                                                                                                                                                                             
around qq"foo" => sub {                                                                                                                                                                                   
        return 1;                                                                                                                                                                                         
};                                                                                                                                                                                                        
                                                                                                                                                                                                          
sub foo {                                                                                                                                                                                                 
        'hello';                                                                                                                                                                                          
}                                                                                                                                                                                                         
$ countperl test.pl                                                                                                                                                                                       
Can't locate object method "literal" via package "PPI::Token::Quote::Interpolate" at /usr/local/share/perl/5.34.0/Perl/Metrics/Simple/Analysis/File.pm line 432.                                          
$ vi test.pl                                                                                                                                                                                              
$ cat test.pl                                                                                                                                                                                             
around "foo" => sub {                                                                                                                                                                                     
        return 1;                                                                                                                                                                                         
};                                                                                                                                                                                                        
                                                                                                                                                                                                          
sub foo {                                                                                                                                                                                                 
        'hello';                                                                                                                                                                                          
}                                                                                                                                                                                                         
$ countperl test.pl                                                                                                                                                                                       
Can't locate object method "literal" via package "PPI::Token::Quote::Double" at /usr/local/share/perl/5.34.0/Perl/Metrics/Simple/Analysis/File.pm line 432.                                               
$ vi test.pl                                                                                                                                                                                              
$ cat test.pl                                                                                                                                                                                             
around 'foo' => sub {                                                                                                                                                                                     
        return 1;                                                                                                                                                                                         
};                                                                                                                                                                                                        
                                                                                                                                                                                                          
sub foo {                                                                                                                                                                                                 
        'hello';                                                                                                                                                                                          
}                                                                                                                                                                                                         
$ countperl test.pl                                                                                                                                                                                       
Perl files found: 1                                                                                                                                                                                       
                                                                                                                                                                                                          
Counts                                                                                                                                                                                                    
------                                                                                                                                                                                                    
total code lines:         6                                                                                                                                                                               
lines of non-sub code:    0                                                                                                                                                                               
packages found:           0                                                                                                                                                                               
subs/methods:             2                        
...
$ vi test.pl
$ cat test.pl
around foo => sub {
        return 1;
};

sub foo { 
        'hello';
}
$ countperl test.pl 
Perl files found: 1

Counts
------
total code lines:         6
lines of non-sub code:    0
packages found:           0
subs/methods:             2
...

Test::Compile usage

I observe two deficiencies in t/000_compile.t:

First, you raised Test::Compile minimal version in Build.PL recently, but you forgot to add the version into "use Test::Compile" in the test. If a user downgrades Test::Compile between running Build.PL and t/000_compile.t, the test will be run with wrong Test::Compile. In other words, the minimal versions should be specified in code. Not only in metadata. You can fix it with:

-use Test::Compile;
+use Test::Compile v1.1.0;

Second, the test checks countperl script twice:

$test->all_files_ok();
pl_file_ok('bin/countperl');

all_files_ok() simply iterates over all Perl scripts files:

$ perl -e 'use Test::Compile; Test::Compile->new->all_files_ok()'
ok 1 - blib/lib/Perl/Metrics/Simple.pm compiles
ok 2 - blib/lib/Perl/Metrics/Simple/Output.pm compiles
ok 3 - blib/lib/Perl/Metrics/Simple/Analysis.pm compiles
ok 4 - blib/lib/Perl/Metrics/Simple/Output/JSON.pm compiles
ok 5 - blib/lib/Perl/Metrics/Simple/Output/HTML.pm compiles
ok 6 - blib/lib/Perl/Metrics/Simple/Output/PlainText.pm compiles
ok 7 - blib/lib/Perl/Metrics/Simple/Analysis/File.pm compiles
ok 8 - blib/script/countperl compiles
# Tests were run but no plan was declared and done_testing() was not seen.

So you test the script twice. You can fix it by removing the direct pl_file_ok() call.

Recognise "method" keyword as a subroutine

I've been using Perl::Metrics::Simple to automatically measure the complexity of a lot of my CPAN code using GitHub Actions (see workflow file here.

Today, I looked at one of the reports for App::MergeCal (see the "run countperl" job). I spotted that the code had a rather high complexity because it's all counted as "code not in named subroutines". I assume that's because I'm using the new perlclass feature and most of my code is in methods, not subroutines.

So this is just here to alert you to the issue. My plan is to look at your code and see if I can work out how to fix this and send you a pull request over the next couple of days.

countperl has incorrect import statement `use Perl::Metrics::Simple qw(0.13);`

See CPAN testers report:
http://www.cpantesters.org/cpan/report/e271e8d0-32ac-11ee-b677-ceaa1f6f0ce4

# Attempt to call undefined import method with arguments via package "Perl::Metrics::Simple" (Perhaps you forgot to load the package?) at blib/script/countperl line 7.
# BEGIN failed--compilation aborted at blib/script/countperl line 7.

The problem line is: use Perl::Metrics::Simple qw(0.13);
where the use of the quoted-words for the VERSION might be causing the issue.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.