r57878 - in /branches/upstream/libperl-metrics-simple-perl/current: ./ bin/ lib/Perl/Metrics/ lib/Perl/Metrics/Simple/ lib/Perl/Metrics/Simple/Analysis/ t/ t/lib/Perl/Metrics/Simple/
jawnsy-guest at users.alioth.debian.org
jawnsy-guest at users.alioth.debian.org
Fri May 14 00:51:54 UTC 2010
Author: jawnsy-guest
Date: Fri May 14 00:51:48 2010
New Revision: 57878
URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=57878
Log:
[svn-upgrade] Integrating new upstream version, libperl-metrics-simple-perl (0.15)
Modified:
branches/upstream/libperl-metrics-simple-perl/current/Changes
branches/upstream/libperl-metrics-simple-perl/current/MANIFEST.SKIP
branches/upstream/libperl-metrics-simple-perl/current/META.yml
branches/upstream/libperl-metrics-simple-perl/current/bin/countperl
branches/upstream/libperl-metrics-simple-perl/current/lib/Perl/Metrics/Simple.pm
branches/upstream/libperl-metrics-simple-perl/current/lib/Perl/Metrics/Simple/Analysis.pm
branches/upstream/libperl-metrics-simple-perl/current/lib/Perl/Metrics/Simple/Analysis/File.pm
branches/upstream/libperl-metrics-simple-perl/current/t/0040_statistics.t
branches/upstream/libperl-metrics-simple-perl/current/t/0050_file.t
branches/upstream/libperl-metrics-simple-perl/current/t/lib/Perl/Metrics/Simple/TestData.pm
Modified: branches/upstream/libperl-metrics-simple-perl/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libperl-metrics-simple-perl/current/Changes?rev=57878&op=diff
==============================================================================
--- branches/upstream/libperl-metrics-simple-perl/current/Changes (original)
+++ branches/upstream/libperl-metrics-simple-perl/current/Changes Fri May 14 00:51:48 2010
@@ -1,4 +1,37 @@
Revision history for Perl module Perl::Metrics::Simple
+
+0.15
+ Changes for https://rt.cpan.org/Public/Bug/Display.html?id=56441
+ Thanks to Maggie J. Xiong for the inquiry, inspiration and patch.
+
+ You can now set:
+ @Perl::Metrics::Simple::Analysis::File::LOGIC_KEYWORDS and OPERATORS
+ to custom values before creating a new
+ Perl::Metrics::Simple::Analysis::File object.
+
+ Added to the default @LOGIC_KEYWORDS used in calculating complexity:
+ map
+ grep
+
+ Added to the default @LOGIC_OPERATORS used in calculating complexity:
+ !~
+ //
+ <
+ <=>
+ ==
+ =~
+ >
+ cmp
+ eq
+ gt
+ lt
+ ne
+ ~~
+
+ Added two accessors on Perl::Metrics::Simple::Analysis::File to obtain
+ the values in use:
+ logic_keywords()
+ logic_operators()
0.14
Allow using a ref-to-SCALAR of file contents instead of a file path.
Modified: branches/upstream/libperl-metrics-simple-perl/current/MANIFEST.SKIP
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libperl-metrics-simple-perl/current/MANIFEST.SKIP?rev=57878&op=diff
==============================================================================
--- branches/upstream/libperl-metrics-simple-perl/current/MANIFEST.SKIP (original)
+++ branches/upstream/libperl-metrics-simple-perl/current/MANIFEST.SKIP Fri May 14 00:51:48 2010
@@ -11,3 +11,4 @@
\.tar\.gz$
^Perl-Metrics-Simple
.DS_Store
+^MYMETA.yml$
Modified: branches/upstream/libperl-metrics-simple-perl/current/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libperl-metrics-simple-perl/current/META.yml?rev=57878&op=diff
==============================================================================
--- branches/upstream/libperl-metrics-simple-perl/current/META.yml (original)
+++ branches/upstream/libperl-metrics-simple-perl/current/META.yml Fri May 14 00:51:48 2010
@@ -1,11 +1,6 @@
---
-name: Perl-Metrics-Simple
-version: 0.14
+abstract: 'Count packages, subs, lines, etc. of many files.'
author: []
-abstract: 'Count packages, subs, lines, etc. of many files.'
-license: perl
-resources:
- license: http://dev.perl.org/licenses/
build_requires:
Data::Dumper: 0
File::Spec: 0
@@ -13,6 +8,26 @@
Readonly: 1.03
Test::Pod: 1
Test::Pod::Coverage: 1.04
+configure_requires:
+ Module::Build: 0.36
+generated_by: 'Module::Build version 0.3607'
+license: perl
+meta-spec:
+ url: http://module-build.sourceforge.net/META-spec-v1.4.html
+ version: 1.4
+name: Perl-Metrics-Simple
+provides:
+ Perl::Metrics::Simple:
+ file: lib/Perl/Metrics/Simple.pm
+ version: 0.15
+ Perl::Metrics::Simple::Analysis:
+ file: lib/Perl/Metrics/Simple/Analysis.pm
+ version: 0.15
+ Perl::Metrics::Simple::Analysis::File:
+ file: lib/Perl/Metrics/Simple/Analysis/File.pm
+ version: 0.15
+recommends:
+ Readonly::XS: 1.02
requires:
Carp: 0
Data::Dumper: 0
@@ -25,21 +40,6 @@
Statistics::Basic::Mean: 0
Statistics::Basic::Median: 0
Statistics::Basic::StdDev: 0
-recommends:
- Readonly::XS: 1.02
-configure_requires:
- Module::Build: 0.35
-provides:
- Perl::Metrics::Simple:
- file: lib/Perl/Metrics/Simple.pm
- version: 0.14
- Perl::Metrics::Simple::Analysis:
- file: lib/Perl/Metrics/Simple/Analysis.pm
- version: 0.14
- Perl::Metrics::Simple::Analysis::File:
- file: lib/Perl/Metrics/Simple/Analysis/File.pm
- version: 0.14
-generated_by: Module::Build version 0.35
-meta-spec:
- url: http://module-build.sourceforge.net/META-spec-v1.4.html
- version: 1.4
+resources:
+ license: http://dev.perl.org/licenses/
+version: 0.15
Modified: branches/upstream/libperl-metrics-simple-perl/current/bin/countperl
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libperl-metrics-simple-perl/current/bin/countperl?rev=57878&op=diff
==============================================================================
--- branches/upstream/libperl-metrics-simple-perl/current/bin/countperl (original)
+++ branches/upstream/libperl-metrics-simple-perl/current/bin/countperl Fri May 14 00:51:48 2010
@@ -1,10 +1,10 @@
#!/usr/bin/perl
-# $Header: /Library/VersionControl/CVS/Perl-Metrics-Simple/bin/countperl,v 1.10 2010/02/07 20:59:07 matisse Exp $
-# $Revision: 1.10 $
+# $Header: /Library/VersionControl/CVS/Perl-Metrics-Simple/bin/countperl,v 1.12 2010/05/09 18:02:28 matisse Exp $
+# $Revision: 1.12 $
# $Author: matisse $
# $Source: /Library/VersionControl/CVS/Perl-Metrics-Simple/bin/countperl,v $
-# $Date: 2010/02/07 20:59:07 $
+# $Date: 2010/05/09 18:02:28 $
###############################################################################
package main;
@@ -14,7 +14,7 @@
use Perl::Metrics::Simple qw(0.13);
use Pod::Usage;
-our $VERSION = 0.14;
+our $VERSION = 0.15;
if ( !@ARGV ) {
pod2usage( -verbose => 1 );
@@ -75,17 +75,17 @@
my @sorted_subs = sort _by_complexity(), @{ $analysis->subs },
@main_from_each_file;
-my $header = join( "\t", 'complexity', 'sub', 'path', 'size' );
+my $header = join "\t", 'complexity', 'sub', 'path', 'size';
$header .= "\n";
print "$header"
- || Carp::croak('Could not print to currently selectd filehandle.');
+ || Carp::croak 'Could not print to currently selectd filehandle.';
foreach my $sub (@sorted_subs) {
my %sub_hash = %{$sub};
- my $line = join( "\t",
- @sub_hash{ 'mccabe_complexity', 'name', 'path', 'lines' } );
+ my $line = join "\t",
+ @sub_hash{ 'mccabe_complexity', 'name', 'path', 'lines' };
$line .= "\n";
print "$line"
- || Carp::croak('Could not print to currently selected file handle.');
+ || Carp::croak 'Could not print to currently selected file handle.';
}
exit;
@@ -214,7 +214,7 @@
=over 4
-=item L<Perl::Metrics::Simple> 0.03 (which depends upon L<PPI>.)
+=item L<Perl::Metrics::Simple> 0.13 (which depends upon L<PPI>.)
=item L<Pod::Usage>
Modified: branches/upstream/libperl-metrics-simple-perl/current/lib/Perl/Metrics/Simple.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libperl-metrics-simple-perl/current/lib/Perl/Metrics/Simple.pm?rev=57878&op=diff
==============================================================================
--- branches/upstream/libperl-metrics-simple-perl/current/lib/Perl/Metrics/Simple.pm (original)
+++ branches/upstream/libperl-metrics-simple-perl/current/lib/Perl/Metrics/Simple.pm Fri May 14 00:51:48 2010
@@ -1,8 +1,8 @@
-# $Header: /Library/VersionControl/CVS/Perl-Metrics-Simple/lib/Perl/Metrics/Simple.pm,v 1.21 2010/02/07 20:59:07 matisse Exp $
-# $Revision: 1.21 $
+# $Header: /Library/VersionControl/CVS/Perl-Metrics-Simple/lib/Perl/Metrics/Simple.pm,v 1.23 2010/05/09 18:02:28 matisse Exp $
+# $Revision: 1.23 $
# $Author: matisse $
# $Source: /Library/VersionControl/CVS/Perl-Metrics-Simple/lib/Perl/Metrics/Simple.pm,v $
-# $Date: 2010/02/07 20:59:07 $
+# $Date: 2010/05/09 18:02:28 $
###############################################################################
package Perl::Metrics::Simple;
@@ -21,7 +21,7 @@
use Perl::Metrics::Simple::Analysis::File;
use Readonly;
-our $VERSION = '0.14';
+our $VERSION = '0.15';
Readonly::Scalar our $PERL_FILE_SUFFIXES => qr{ \. (:? pl | pm | t ) }sxmi;
Readonly::Scalar our $SKIP_LIST_REGEX => qr{ \.svn | \. git | _darcs | CVS }sxmi;
@@ -67,8 +67,8 @@
my $wanted = sub {
return if $self->should_be_skipped($File::Find::name);
if ( $self->is_perl_file($File::Find::name) )
- { ## no critic ProhibitPackageVars
- push @files, $File::Find::name; ## no critic ProhibitPackageVars
+ {
+ push @files, $File::Find::name; ## no critic (ProhibitPackageVars)
}
};
Modified: branches/upstream/libperl-metrics-simple-perl/current/lib/Perl/Metrics/Simple/Analysis.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libperl-metrics-simple-perl/current/lib/Perl/Metrics/Simple/Analysis.pm?rev=57878&op=diff
==============================================================================
--- branches/upstream/libperl-metrics-simple-perl/current/lib/Perl/Metrics/Simple/Analysis.pm (original)
+++ branches/upstream/libperl-metrics-simple-perl/current/lib/Perl/Metrics/Simple/Analysis.pm Fri May 14 00:51:48 2010
@@ -1,8 +1,8 @@
-# $Header: /Library/VersionControl/CVS/Perl-Metrics-Simple/lib/Perl/Metrics/Simple/Analysis.pm,v 1.16 2010/02/07 20:59:07 matisse Exp $
-# $Revision: 1.16 $
+# $Header: /Library/VersionControl/CVS/Perl-Metrics-Simple/lib/Perl/Metrics/Simple/Analysis.pm,v 1.18 2010/05/09 18:02:28 matisse Exp $
+# $Revision: 1.18 $
# $Author: matisse $
# $Source: /Library/VersionControl/CVS/Perl-Metrics-Simple/lib/Perl/Metrics/Simple/Analysis.pm,v $
-# $Date: 2010/02/07 20:59:07 $
+# $Date: 2010/05/09 18:02:28 $
###############################################################################
package Perl::Metrics::Simple::Analysis;
@@ -16,16 +16,16 @@
use Statistics::Basic::Mean;
use Statistics::Basic::Median;
-our $VERSION = '0.14';
-
-my %AnalysisData = ();
-my %Files = ();
-my %FileStats = ();
-my %Lines = ();
-my %Main = ();
-my %Packages = ();
-my %Subs = ();
-my %SummaryStats = ();
+our $VERSION = '0.15';
+
+my %_ANALYSIS_DATA = ();
+my %_FILES = ();
+my %_FILE_STATS = ();
+my %_LINES = ();
+my %_MAIN = ();
+my %_PACKAGES = ();
+my %_SUBS = ();
+my %_SUMMARY_STATS = ();
sub new {
my ( $class, $analysis_data ) = @_;
@@ -40,12 +40,12 @@
sub files {
my ($self) = @_;
- return $Files{$self};
+ return $_FILES{$self};
}
sub data {
my $self = shift;
- return $AnalysisData{$self};
+ return $_ANALYSIS_DATA{$self};
}
sub file_count {
@@ -55,12 +55,12 @@
sub lines {
my $self = shift;
- return $Lines{$self};
+ return $_LINES{$self};
}
sub packages {
my ($self) = @_;
- return $Packages{$self};
+ return $_PACKAGES{$self};
}
sub package_count {
@@ -70,22 +70,22 @@
sub file_stats {
my $self = shift;
- return $FileStats{$self};
+ return $_FILE_STATS{$self};
}
sub main_stats {
my $self = shift;
- return $Main{$self};
+ return $_MAIN{$self};
}
sub summary_stats {
my $self = shift;
- return $SummaryStats{$self};
+ return $_SUMMARY_STATS{$self};
}
sub subs {
my ($self) = @_;
- return $Subs{$self};
+ return $_SUBS{$self};
}
sub sub_count {
@@ -111,7 +111,7 @@
sub _init {
my ( $self, $file_objects ) = @_;
- $AnalysisData{$self} = $file_objects;
+ $_ANALYSIS_DATA{$self} = $file_objects;
my @all_files = ();
my @packages = ();
@@ -132,13 +132,13 @@
push @subs, @{ $file->subs };
}
- $FileStats{$self} = \@file_stats;
- $Files{$self} = \@all_files;
- $Main{$self} = \%main_stats;
- $Packages{$self} = \@packages;
- $Lines{$self} = $lines;
- $Subs{$self} = \@subs;
- $SummaryStats{$self} = $self->_make_summary_stats();
+ $_FILE_STATS{$self} = \@file_stats;
+ $_FILES{$self} = \@all_files;
+ $_MAIN{$self} = \%main_stats;
+ $_PACKAGES{$self} = \@packages;
+ $_LINES{$self} = $lines;
+ $_SUBS{$self} = \@subs;
+ $_SUMMARY_STATS{$self} = $self->_make_summary_stats();
return 1;
}
Modified: branches/upstream/libperl-metrics-simple-perl/current/lib/Perl/Metrics/Simple/Analysis/File.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libperl-metrics-simple-perl/current/lib/Perl/Metrics/Simple/Analysis/File.pm?rev=57878&op=diff
==============================================================================
--- branches/upstream/libperl-metrics-simple-perl/current/lib/Perl/Metrics/Simple/Analysis/File.pm (original)
+++ branches/upstream/libperl-metrics-simple-perl/current/lib/Perl/Metrics/Simple/Analysis/File.pm Fri May 14 00:51:48 2010
@@ -1,8 +1,8 @@
-# $Header: /Library/VersionControl/CVS/Perl-Metrics-Simple/lib/Perl/Metrics/Simple/Analysis/File.pm,v 1.20 2010/02/07 20:59:07 matisse Exp $
-# $Revision: 1.20 $
+# $Header: /Library/VersionControl/CVS/Perl-Metrics-Simple/lib/Perl/Metrics/Simple/Analysis/File.pm,v 1.23 2010/05/09 18:02:28 matisse Exp $
+# $Revision: 1.23 $
# $Author: matisse $
# $Source: /Library/VersionControl/CVS/Perl-Metrics-Simple/lib/Perl/Metrics/Simple/Analysis/File.pm,v $
-# $Date: 2010/02/07 20:59:07 $
+# $Date: 2010/05/09 18:02:28 $
###############################################################################
package Perl::Metrics::Simple::Analysis::File;
@@ -17,25 +17,67 @@
use PPI::Document;
use Readonly;
-our $VERSION = '0.14';
+our $VERSION = '0.15';
Readonly::Scalar my $ALL_NEWLINES_REGEX =>
qr/ ( \Q$INPUT_RECORD_SEPARATOR\E ) /sxm;
-Readonly::Array our @LOGIC_OPERATORS =>
- qw( ! && || ||= &&= or and xor not ? <<= >>= );
-Readonly::Hash our %LOGIC_OPERATORS => hashify(@LOGIC_OPERATORS);
-
-Readonly::Array our @LOGIC_KEYWORDS =>
- qw( for foreach goto if else elsif last next unless until while );
-Readonly::Hash our %LOGIC_KEYWORDS => hashify(@LOGIC_KEYWORDS);
+Readonly::Array our @DEFAULT_LOGIC_OPERATORS => qw(
+ !
+ !~
+ &&
+ &&=
+ //
+ <
+ <<=
+ <=>
+ ==
+ =~
+ >
+ >>=
+ ?
+ and
+ cmp
+ eq
+ gt
+ lt
+ ne
+ not
+ or
+ xor
+ ||
+ ||=
+ ~~
+ );
+
+Readonly::Array our @DEFAULT_LOGIC_KEYWORDS => qw(
+ else
+ elsif
+ for
+ foreach
+ goto
+ grep
+ if
+ last
+ map
+ next
+ unless
+ until
+ while
+ );
Readonly::Scalar my $LAST_CHARACTER => -1;
+our (@LOGIC_KEYWORDS, @LOGIC_OPERATORS); # For user-supplied values;
+
+our (%LOGIC_KEYWORDS, %LOGIC_OPERATORS); # Populated in _init()
+
# Private instance variables:
-my %Path = ();
-my %Main_Stats = ();
-my %Subs = ();
-my %Packages = ();
-my %Lines = ();
+my %_PATH = ();
+my %_MAIN_STATS = ();
+my %_SUBS = ();
+my %_PACKAGES = ();
+my %_LINES = ();
+my %_LOGIC_KEYWORDS = ();
+my %_LOGIC_OPERATORS = ();
sub new {
my ( $class, %parameters ) = @_;
@@ -47,9 +89,9 @@
sub _init {
my ( $self, %parameters ) = @_;
- $Path{$self} = $parameters{path};
-
- my $path = $self->path;
+ $_PATH{$self} = $parameters{'path'};
+
+ my $path = $self->path();
my $document;
if (ref $path) {
@@ -73,15 +115,23 @@
my $packages = _get_packages($document);
+ my @logic_keywords = @LOGIC_KEYWORDS ? @LOGIC_KEYWORDS : @DEFAULT_LOGIC_KEYWORDS;
+ %LOGIC_KEYWORDS = hashify(@logic_keywords);
+ $_LOGIC_OPERATORS{$self} = \%LOGIC_KEYWORDS;
+
+ my @logic_operators = @LOGIC_OPERATORS ? @LOGIC_OPERATORS : @DEFAULT_LOGIC_OPERATORS;
+ %LOGIC_OPERATORS = hashify(@logic_operators);
+ $_LOGIC_OPERATORS{$self} = \%LOGIC_OPERATORS;
+
my @sub_analysis = ();
my $sub_elements = $document->find('PPI::Statement::Sub');
@sub_analysis = @{ $self->_iterate_over_subs($sub_elements) };
- $Main_Stats{$self}
+ $_MAIN_STATS{$self}
= $self->analyze_main( $document, $sub_elements, \@sub_analysis );
- $Subs{$self} = \@sub_analysis;
- $Packages{$self} = $packages;
- $Lines{$self} = $self->get_node_length($document);
+ $_SUBS{$self} = \@sub_analysis;
+ $_PACKAGES{$self} = $packages;
+ $_LINES{$self} = $self->get_node_length($document);
return $self;
}
@@ -179,27 +229,37 @@
sub path {
my ($self) = @_;
- return $Path{$self};
+ return $_PATH{$self};
}
sub main_stats {
my ($self) = @_;
- return $Main_Stats{$self};
+ return $_MAIN_STATS{$self};
}
sub subs {
my ($self) = @_;
- return $Subs{$self};
+ return $_SUBS{$self};
}
sub packages {
my ($self) = @_;
- return $Packages{$self};
+ return $_PACKAGES{$self};
}
sub lines {
my ($self) = @_;
- return $Lines{$self};
+ return $_LINES{$self};
+}
+
+sub logic_keywords {
+ my ($self) = @_;
+ return wantarray ? @{$_LOGIC_KEYWORDS{$self}} : $_LOGIC_KEYWORDS{$self};
+}
+
+sub logic_operators {
+ my ($self) = @_;
+ return wantarray ? @{$_LOGIC_OPERATORS{$self}} : $_LOGIC_OPERATORS{$self};
}
sub measure_complexity {
@@ -401,6 +461,16 @@
Returns the hashref generated by I<analyze_main> without re-analyzing document.
+=head2 logic_keywords
+
+Returns an array (in array context) or ref-to-ARRAY of the keywords
+used in calculating complexity. See I<Logic Keywords> section below.
+
+=head2 logic_operators
+
+Returns an array (in array context) or ref-to-ARRAY of the operators
+used in calculating complexity. See I<Logic Operators> section below.
+
=head2 measure_complexity
Takes a B<PPI> element and measures an approximation of the
@@ -417,15 +487,61 @@
=head3 Logic operators:
-See I<@Perl::Metrics::Simple::Analysis::File::LOGIC_OPERATORS>
-
- ! && || ||= &&= or and xor not ? <<= >>=
+The default list is:
+
+I<@Perl::Metrics::Simple::Analysis::File::DEFAULT_LOGIC_OPERATORS>
+
+ !
+ !~
+ &&
+ &&=
+ //
+ <
+ <<=
+ <=>
+ ==
+ =~
+ >
+ >>=
+ ?
+ and
+ cmp
+ eq
+ gt
+ lt
+ ne
+ not
+ or
+ xor
+ ||
+ ||=
+ ~~
+
+You can supply your own list by setting:
+I<@Perl::Metrics::Simple::Analysis::File::LOGIC_OPERATORS> before creating a
+new object.
=head3 Logic keywords:
-See I<@Perl::Metrics::Simple::Analysis::File::LOGIC_KEYWORDS>
-
- for foreach goto if else elsif last next unless until while
+I<@Perl::Metrics::Simple::Analysis::File::DEFAULT_LOGIC_KEYWORDS>
+
+ else
+ elsif
+ for
+ foreach
+ goto
+ grep
+ if
+ last
+ map
+ next
+ unless
+ until
+ while
+
+You can supply your own list by setting:
+I<@Perl::Metrics::Simple::Analysis::File::LOGIC_KEYWORDS> before creating a
+new object.
=head3 Examples of Complexity
Modified: branches/upstream/libperl-metrics-simple-perl/current/t/0040_statistics.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libperl-metrics-simple-perl/current/t/0040_statistics.t?rev=57878&op=diff
==============================================================================
--- branches/upstream/libperl-metrics-simple-perl/current/t/0040_statistics.t (original)
+++ branches/upstream/libperl-metrics-simple-perl/current/t/0040_statistics.t Fri May 14 00:51:48 2010
@@ -64,12 +64,12 @@
my $sub_complexity = $analysis->summary_stats->{sub_complexity};
cmp_ok( $sub_complexity->{min}, '==', 1, 'minimum sub complexity.' );
- cmp_ok( $sub_complexity->{max}, '==', 6, 'maximum sub complexity.' );
+ cmp_ok( $sub_complexity->{max}, '==', 8, 'maximum sub complexity.' );
cmp_ok( $sub_complexity->{mean},
- '==', 2.6, 'mean (average) sub complexity.' );
+ '==', 3.2, 'mean (average) sub complexity.' );
cmp_ok( $sub_complexity->{median}, '==', 1, 'median sub complexity.' );
cmp_ok( $sub_complexity->{standard_deviation},
- '==', 2.06, 'standard deviation of sub complexity.' );
+ '==', 2.86, 'standard deviation of sub complexity.' );
my $main_complexity = $analysis->summary_stats->{main_complexity};
cmp_ok( $main_complexity->{min}, '==', 0, 'minimum main complexity.' );
Modified: branches/upstream/libperl-metrics-simple-perl/current/t/0050_file.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libperl-metrics-simple-perl/current/t/0050_file.t?rev=57878&op=diff
==============================================================================
--- branches/upstream/libperl-metrics-simple-perl/current/t/0050_file.t (original)
+++ branches/upstream/libperl-metrics-simple-perl/current/t/0050_file.t Fri May 14 00:51:48 2010
@@ -14,13 +14,14 @@
use PPI;
use Perl::Metrics::Simple::Analysis::File;
use Readonly;
-use Test::More tests => 17;
+use Test::More tests => 20;
Readonly::Scalar my $TEST_DIRECTORY => "$Bin/test_files";
Readonly::Scalar my $EMPTY_STRING => q{};
test_get_node_length();
test_measure_complexity();
+test_measure_complexity_with_custom_settings();
test_is_hash_key();
exit;
@@ -68,10 +69,72 @@
$file_counter->measure_complexity($print_statement_doc);
is( $print_statement_complexity, 1, 'Complexity of print statement is 1' );
- my $basic_if_code = 'if ($a > $b) { return 1; }';
+ my $basic_if_code = 'if ($boolean) { return 1; }';
my $basic_if_doc = PPI::Document->new( \$basic_if_code );
my $basic_if_complexity = $file_counter->measure_complexity($basic_if_doc);
is( $basic_if_complexity, 2, 'Complexity of basic "if" block is 2' );
+
+ return 1;
+}
+
+sub test_measure_complexity_with_custom_settings {
+ my $test_file = "$TEST_DIRECTORY/not_a_perl_file";
+ my $file_counter =
+ Perl::Metrics::Simple::Analysis::File->new(path => $test_file);
+
+ my $code_with_if_plus_map = <<'EOS';
+ if ($boolean) {
+ @new_list = map { do_something($_) } @old_list;
+ $a++;
+ }
+ $b = rand;
+ return $a || $b;
+EOS
+
+ my $doc_with_if_plus_map = PPI::Document->new( \$code_with_if_plus_map );
+
+ my $if_plus_map_complexity = $file_counter->measure_complexity($doc_with_if_plus_map);
+ my $expected_default_complexity = 4;
+ is( $if_plus_map_complexity,
+ $expected_default_complexity,
+ 'Using default @LOGIC_KEYWORDS and @LOGIC_OPERATORS'
+ );
+
+ {
+ # Add 'rand' as a logic keyword
+ no warnings qw(once);
+ local @Perl::Metrics::Simple::Analysis::File::LOGIC_KEYWORDS =
+ ( @Perl::Metrics::Simple::Analysis::File::DEFAULT_LOGIC_KEYWORDS,
+ 'rand' );
+
+ $file_counter =
+ Perl::Metrics::Simple::Analysis::File->new(path => $test_file);
+
+ my $got_custom_complexity = $file_counter->measure_complexity($doc_with_if_plus_map);
+ my $expected_with_custom_keywords = 5;
+ is( $got_custom_complexity,
+ $expected_with_custom_keywords,
+ 'Using custom @LOGIC_KEYWORDS'
+ );
+
+ # Add '++' as a logic operator.
+ local @Perl::Metrics::Simple::Analysis::File::LOGIC_OPERATORS =
+ (
+ @Perl::Metrics::Simple::Analysis::File::DEFAULT_LOGIC_OPERATORS,
+ '++'
+ );
+
+ my $custom_counter =
+ Perl::Metrics::Simple::Analysis::File->new(path => $test_file);
+
+ $got_custom_complexity = $custom_counter->measure_complexity($doc_with_if_plus_map);
+ my $expected_with_custom_keywords_and_operators = 6;
+ is( $got_custom_complexity,
+ $expected_with_custom_keywords_and_operators,
+ 'Using custom @LOGIC_OPERATORS and @LOGIC_KEYWORDS'
+ );
+ }
+
return 1;
}
Modified: branches/upstream/libperl-metrics-simple-perl/current/t/lib/Perl/Metrics/Simple/TestData.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libperl-metrics-simple-perl/current/t/lib/Perl/Metrics/Simple/TestData.pm?rev=57878&op=diff
==============================================================================
--- branches/upstream/libperl-metrics-simple-perl/current/t/lib/Perl/Metrics/Simple/TestData.pm (original)
+++ branches/upstream/libperl-metrics-simple-perl/current/t/lib/Perl/Metrics/Simple/TestData.pm Fri May 14 00:51:48 2010
@@ -157,13 +157,13 @@
{
name => 'foo',
lines => 9,
- mccabe_complexity => 6,
+ mccabe_complexity => 8,
path => "$test_directory/Perl/Code/Analyze/Test/Module.pm",
},
{
name => 'say_hello',
lines => 9,
- mccabe_complexity => 4,
+ mccabe_complexity => 5,
path => "$test_directory/Perl/Code/Analyze/Test/Module.pm",
},
],
More information about the Pkg-perl-cvs-commits
mailing list