matisse / perl-metrics-simple Goto Github PK
View Code? Open in Web Editor NEWStatic analysis of Perl code. Counts complexity, packages, subs, lines, etc. of many files.
License: Other
Static analysis of Perl code. Counts complexity, packages, subs, lines, etc. of many files.
License: Other
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
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
...
META.yml does not have a bugtracker: key to github in resources:, so links to report issues are not to github but to rt.cpan.org.
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.
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.
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.