| Test-Apocalypse documentation | Contained in the Test-Apocalypse distribution. |
Test::Apocalypse::PerlMetrics - Plugin for Perl::Metrics::Simple
This document describes v1.002 of Test::Apocalypse::PerlMetrics - released April 21, 2011 as part of Test-Apocalypse.
Encapsulates Perl::Metrics::Simple functionality. Enable TEST_VERBOSE to get a diag() output of some metrics.
Please see those modules/websites for more information related to this module.
Apocalypse <APOCAL@cpan.org>
This software is copyright (c) 2011 by Apocalypse.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
The full text of the license can be found in the LICENSE file included with this distribution.
BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
| Test-Apocalypse documentation | Contained in the Test-Apocalypse distribution. |
# # This file is part of Test-Apocalypse # # This software is copyright (c) 2011 by Apocalypse. # # This is free software; you can redistribute it and/or modify it under # the same terms as the Perl 5 programming language system itself. # use strict; use warnings; package Test::Apocalypse::PerlMetrics; BEGIN { $Test::Apocalypse::PerlMetrics::VERSION = '1.002'; } BEGIN { $Test::Apocalypse::PerlMetrics::AUTHORITY = 'cpan:APOCAL'; } # ABSTRACT: Plugin for Perl::Metrics::Simple use Test::More; use Perl::Metrics::Simple 0.13; sub do_test { plan tests => 1; my $analzyer = Perl::Metrics::Simple->new; my $analysis = $analzyer->analyze_files( 'lib/' ); my $numdisplay = 10; if ( ok( $analysis->file_count(), 'Analyzed at least one file' ) ) { # only print extra stuff if necessary if ( $ENV{TEST_VERBOSE} ) { diag( '-- Perl Metrics Summary --' ); diag( ' File Count: ' . $analysis->file_count ); diag( ' Package Count: ' . $analysis->package_count ); diag( ' Subroutine Count: ' . $analysis->sub_count ); diag( ' Total Code Lines: ' . $analysis->lines ); diag( ' Non-Sub Lines: ' . $analysis->main_stats->{'lines'} ); diag( '-- Subrotuine Metrics Summary --' ); my $summary_stats = $analysis->summary_stats; diag( ' Min: lines(' . $summary_stats->{sub_length}->{min} . ') McCabe(' . $summary_stats->{sub_complexity}->{min} . ')' ); diag( ' Max: lines(' . $summary_stats->{sub_length}->{max} . ') McCabe(' . $summary_stats->{sub_complexity}->{max} . ')' ); diag( ' Mean: lines(' . $summary_stats->{sub_length}->{mean} . ') McCabe(' . $summary_stats->{sub_complexity}->{mean} . ')' ); diag( ' Standard Deviation: lines(' . $summary_stats->{sub_length}->{standard_deviation} . ') McCabe(' . $summary_stats->{sub_complexity}->{standard_deviation} . ')' ); diag( ' Median: lines(' . $summary_stats->{sub_length}->{median} . ') McCabe(' . $summary_stats->{sub_complexity}->{median} . ')' ); diag( "-- Top$numdisplay subroutines by McCabe Complexity --" ); my @sorted_subs = reverse sort { $a->{'mccabe_complexity'} <=> $b->{'mccabe_complexity'} } @{ $analysis->subs }; foreach my $i ( 0 .. ( $numdisplay - 1 ) ) { last if ! defined $sorted_subs[$i]; diag( ' ' . $sorted_subs[$i]->{'path'} . ':' . $sorted_subs[$i]->{'name'} . ' ->' . ' McCabe(' . $sorted_subs[$i]->{'mccabe_complexity'} . ')' . ' lines(' . $sorted_subs[$i]->{'lines'} . ')' ); } diag( "-- Top$numdisplay subroutines by lines --" ); @sorted_subs = reverse sort { $a->{'lines'} <=> $b->{'lines'} } @sorted_subs; foreach my $i ( 0 .. ( $numdisplay - 1 ) ) { last if ! defined $sorted_subs[$i]; diag( ' ' . $sorted_subs[$i]->{'path'} . ':' . $sorted_subs[$i]->{'name'} . ' ->' . ' lines(' . $sorted_subs[$i]->{'lines'} . ')' . ' McCabe(' . $sorted_subs[$i]->{'mccabe_complexity'} . ')' ); } #require Data::Dumper; #diag( 'Summary Stats: ' . Data::Dumper::Dumper( $analysis->summary_stats ) ); #diag( 'File Stats: ' . Data::Dumper::Dumper( $analysis->file_stats ) ); } } return; } 1; __END__