File Coverage

blib/lib/Test/Apocalypse/PerlMetrics.pm
Criterion Covered Total %
statement 20 46 43.4
branch 2 8 25.0
condition n/a
subroutine 6 6 100.0
pod 0 1 0.0
total 28 61 45.9


line stmt bran cond sub pod time code
1             #
2             # This file is part of Test-Apocalypse
3             #
4             # This software is copyright (c) 2014 by Apocalypse.
5             #
6             # This is free software; you can redistribute it and/or modify it under
7             # the same terms as the Perl 5 programming language system itself.
8             #
9 38     38   11330899 use strict; use warnings;
  38     38   56  
  38         1403  
  38         164  
  38         40  
  38         1758  
10             package Test::Apocalypse::PerlMetrics;
11             $Test::Apocalypse::PerlMetrics::VERSION = '1.006';
12             BEGIN {
13 38     38   693 $Test::Apocalypse::PerlMetrics::AUTHORITY = 'cpan:APOCAL';
14             }
15              
16             # ABSTRACT: Plugin for Perl::Metrics::Simple
17              
18 38     38   216 use Test::More;
  38         38  
  38         1328  
19 38     38   26238 use Perl::Metrics::Simple 0.13;
  38         1553539  
  38         303  
20              
21             sub do_test {
22 37     37 0 185 plan tests => 1;
23 37         6475 my $analzyer = Perl::Metrics::Simple->new;
24 37         1221 my $analysis = $analzyer->analyze_files( 'lib/' );
25 37         231214628 my $numdisplay = 10;
26              
27 37 50       185 if ( ok( $analysis->file_count(), 'Analyzed at least one file' ) ) {
28             # only print extra stuff if necessary
29 37 50       22348 if ( $ENV{TEST_VERBOSE} ) {
30 0         0 diag( '-- Perl Metrics Summary --' );
31 0         0 diag( ' File Count: ' . $analysis->file_count );
32 0         0 diag( ' Package Count: ' . $analysis->package_count );
33 0         0 diag( ' Subroutine Count: ' . $analysis->sub_count );
34 0         0 diag( ' Total Code Lines: ' . $analysis->lines );
35 0         0 diag( ' Non-Sub Lines: ' . $analysis->main_stats->{'lines'} );
36              
37 0         0 diag( '-- Subrotuine Metrics Summary --' );
38 0         0 my $summary_stats = $analysis->summary_stats;
39 0         0 diag( ' Min: lines(' . $summary_stats->{sub_length}->{min} . ') McCabe(' . $summary_stats->{sub_complexity}->{min} . ')' );
40 0         0 diag( ' Max: lines(' . $summary_stats->{sub_length}->{max} . ') McCabe(' . $summary_stats->{sub_complexity}->{max} . ')' );
41 0         0 diag( ' Mean: lines(' . $summary_stats->{sub_length}->{mean} . ') McCabe(' . $summary_stats->{sub_complexity}->{mean} . ')' );
42 0         0 diag( ' Standard Deviation: lines(' . $summary_stats->{sub_length}->{standard_deviation} . ') McCabe(' . $summary_stats->{sub_complexity}->{standard_deviation} . ')' );
43 0         0 diag( ' Median: lines(' . $summary_stats->{sub_length}->{median} . ') McCabe(' . $summary_stats->{sub_complexity}->{median} . ')' );
44              
45 0         0 diag( "-- Top$numdisplay subroutines by McCabe Complexity --" );
46 0         0 my @sorted_subs = reverse sort { $a->{'mccabe_complexity'} <=> $b->{'mccabe_complexity'} } @{ $analysis->subs };
  0         0  
  0         0  
47 0         0 foreach my $i ( 0 .. ( $numdisplay - 1 ) ) {
48 0 0       0 last if ! defined $sorted_subs[$i];
49              
50 0         0 diag( ' ' . $sorted_subs[$i]->{'path'} . ':' . $sorted_subs[$i]->{'name'} . ' ->' .
51             ' McCabe(' . $sorted_subs[$i]->{'mccabe_complexity'} . ')' .
52             ' lines(' . $sorted_subs[$i]->{'lines'} . ')'
53             );
54             }
55              
56 0         0 diag( "-- Top$numdisplay subroutines by lines --" );
57 0         0 @sorted_subs = reverse sort { $a->{'lines'} <=> $b->{'lines'} } @sorted_subs;
  0         0  
58 0         0 foreach my $i ( 0 .. ( $numdisplay - 1 ) ) {
59 0 0       0 last if ! defined $sorted_subs[$i];
60              
61 0         0 diag( ' ' . $sorted_subs[$i]->{'path'} . ':' . $sorted_subs[$i]->{'name'} . ' ->' .
62             ' lines(' . $sorted_subs[$i]->{'lines'} . ')' .
63             ' McCabe(' . $sorted_subs[$i]->{'mccabe_complexity'} . ')'
64             );
65             }
66              
67             #require Data::Dumper;
68             #diag( 'Summary Stats: ' . Data::Dumper::Dumper( $analysis->summary_stats ) );
69             #diag( 'File Stats: ' . Data::Dumper::Dumper( $analysis->file_stats ) );
70             }
71             }
72              
73 37         999 return;
74             }
75              
76             1;
77              
78             __END__
79              
80             =pod
81              
82             =encoding UTF-8
83              
84             =for :stopwords Apocalypse Niebur Ryan
85              
86             =for Pod::Coverage do_test
87              
88             =head1 NAME
89              
90             Test::Apocalypse::PerlMetrics - Plugin for Perl::Metrics::Simple
91              
92             =head1 VERSION
93              
94             This document describes v1.006 of Test::Apocalypse::PerlMetrics - released October 25, 2014 as part of Test-Apocalypse.
95              
96             =head1 DESCRIPTION
97              
98             Encapsulates L<Perl::Metrics::Simple> functionality. Enable TEST_VERBOSE to get a diag() output of some metrics.
99              
100             =head1 SEE ALSO
101              
102             Please see those modules/websites for more information related to this module.
103              
104             =over 4
105              
106             =item *
107              
108             L<Test::Apocalypse|Test::Apocalypse>
109              
110             =back
111              
112             =head1 AUTHOR
113              
114             Apocalypse <APOCAL@cpan.org>
115              
116             =head1 COPYRIGHT AND LICENSE
117              
118             This software is copyright (c) 2014 by Apocalypse.
119              
120             This is free software; you can redistribute it and/or modify it under
121             the same terms as the Perl 5 programming language system itself.
122              
123             The full text of the license can be found in the
124             F<LICENSE> file included with this distribution.
125              
126             =head1 DISCLAIMER OF WARRANTY
127              
128             THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
129             APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
130             HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
131             OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
132             THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
133             PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
134             IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
135             ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
136              
137             IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
138             WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
139             THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
140             GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
141             USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
142             DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
143             PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
144             EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
145             SUCH DAMAGES.
146              
147             =cut