Metrics-CodeCounter-0.0.1/0000755000076500007650000000000010311707204017657 5ustar johnfraserjohnfraser00000000000000Metrics-CodeCounter-0.0.1/.cvsignore0000644000076500007650000000015210311706026021656 0ustar johnfraserjohnfraser00000000000000blib* Makefile Makefile.old Build _build* pm_to_blib* *.tar.gz .lwpcookies Metrics-CodeCounter-* cover_db Metrics-CodeCounter-0.0.1/._.DS_Store0000400000076500000000000000012210311707612020464 0ustar johnfraserwheel00000000000000Mac OS X  2 R@Metrics-CodeCounter-0.0.1/.DS_Store0000644000076500007650000001400410311707612021344 0ustar johnfraserjohnfraser00000000000000Bud1‡clboollibdsclbooltdsclbooltfwi0blobicnvtfwswlongwticgoblob  @€ @€ @€ @ E‡DSDB ` @€ @€ @Metrics-CodeCounter-0.0.1/Build.PL0000644000076500007650000000071110311706026021153 0ustar johnfraserjohnfraser00000000000000use strict; use warnings; use Module::Build; my $builder = Module::Build->new( module_name => 'Metrics::CodeCounter', license => 'perl', dist_author => 'John Fraser ', dist_version_from => 'lib/Metrics/CodeCounter.pm', requires => { 'Test::More' => 0, 'version' => 0, }, add_to_cleanup => [ 'Metrics-CodeCounter-*' ], ); $builder->create_build_script(); Metrics-CodeCounter-0.0.1/Changes0000644000076500007650000000014310311706026021151 0ustar johnfraserjohnfraser00000000000000Revision history for Metrics-CodeCounter 0.0.1 Tue Sep 13 22:33:58 2005 Initial release. Metrics-CodeCounter-0.0.1/lib/0000755000076500007650000000000010311706040020422 5ustar johnfraserjohnfraser00000000000000Metrics-CodeCounter-0.0.1/lib/._.DS_Store0000400000076500000000000000012210311707612021232 0ustar johnfraserwheel00000000000000Mac OS X  2 R@Metrics-CodeCounter-0.0.1/lib/.DS_Store0000644000076500007650000001400410311707612022112 0ustar johnfraserjohnfraser00000000000000Bud1‡icsdsclboMetricsdsclboolMetricsfwi0blobicnvMetricsfwswlongw  @€ @€ @€ @ E‡DSDB ` @€ @€ @Metrics-CodeCounter-0.0.1/lib/Metrics/0000755000076500007650000000000010311707577022050 5ustar johnfraserjohnfraser00000000000000Metrics-CodeCounter-0.0.1/lib/Metrics/._.DS_Store0000400000076500000000000000012210311707612022640 0ustar johnfraserwheel00000000000000Mac OS X  2 R@Metrics-CodeCounter-0.0.1/lib/Metrics/.DS_Store0000644000076500007650000001400410311707612023520 0ustar johnfraserjohnfraser00000000000000Bud1‡Counte CodeCounterdsclbool CodeCountericgoblob  @€ @€ @€ @ E‡DSDB ` @€ @€ @Metrics-CodeCounter-0.0.1/lib/Metrics/CodeCounter/0000755000076500007650000000000010311707605024252 5ustar johnfraserjohnfraser00000000000000Metrics-CodeCounter-0.0.1/lib/Metrics/CodeCounter/._.DS_Store0000400000076500000000000000012210311707605025054 0ustar johnfraserwheel00000000000000Mac OS X  2 R@Metrics-CodeCounter-0.0.1/lib/Metrics/CodeCounter/.DS_Store0000644000076500007650000001400410311707605025734 0ustar johnfraserjohnfraser00000000000000Bud1%  @€ @€ @€ @ E%DSDB`€ @€ @€ @Metrics-CodeCounter-0.0.1/lib/Metrics/CodeCounter/Standards.pm0000644000076500007650000002277210311704711026540 0ustar johnfraserjohnfraser00000000000000package Metrics::CodeCounter::Standards; use version; $VERSION = qv('0.0.1'); use warnings; use strict; use Carp; use base qw( Exporter ); use XML::Simple; use Data::Dumper; our @EXPORT = qw( load_standards ); sub load_standards{ my ($file) = @_; my $xml_doc = XMLin( $file, ForceArray => 1 ); return evaluate_standards($xml_doc->{standard}); } sub evaluate_standards{ my ($standards) = @_; my $std = {}; # iterate through all elements at this level foreach my $standard (values %{ $standards }){ my $rules = create_rules($standard->{rules}->[0]->{rule}, $standard->{"complex-rules"}->[0]->{"complex-rule"}); foreach my $ext (@{ $standard->{extentions}->[0]->{extention} }){ $std->{ $ext->{value} } = $rules; } } return $std; } sub create_rules{ my($rules, $complex) = @_; my %rule_structure; foreach my $rule (keys %{$rules}){ $rule_structure{$rule} = build_rule($rules->{$rule}->{value}, $rules->{$rule}->{op}); } foreach my $rule (keys %{ $complex }) { $rule_structure{$rule} = build_complex_rule($complex->{$rule}->{"start-value"}, $complex->{$rule}->{"stop-value" }, $complex->{$rule}->{"op" },) ; } return \%rule_structure; } sub build_rule{ my($value, $op) = @_; my $apply = sub{ my ($line) = @_; if ($line =~ /$value/){ return $op; } return "pass"; }; return $apply; } sub build_complex_rule { my($start, $stop, $op) = @_; my $found = 0; my $apply = sub{ my ($line) = @_; if($found){ if ($line =~ /$stop/){ $found = 0; return $op; } return $op; } else{ if ($line =~ /$start/){ $found = 1; return $op; } return 'pass'; } }; return $apply; } 1; # Magic true value required at end of module __END__ =head1 NAME CodeCounter::Standards - Loads and provides counting standards for CodeCounter =head1 VERSION This document describes CodeCounter::Standards version 0.0.1 =head1 SYNOPSIS use Metrics::CodeCounter::Standards; # exports load_standards $standards = load_standards('t/standards.xml'); # figure out the files extention $file =~ /\.(.+)$/; $ext = $1; # pull the rules for that extention (i.e., Perl rules for .pm files) $rules = $standards->{$ext}; # open up some source file and import the lines into # an array open $in, "<", $file; my @lines = <$in>; # iterate through the source line by line foreach my $line (@lines){ my $result; # get rid of whitespace that may interfere $line =~ s/^\s+//; $line =~ s/\s+$//; # apply the rules in order, unless a stop or fail is encounterd for my $rule (keys %{$rules}){ $result = $rules->{$rule}->($line); last if $result ne "pass"; } $count++ if $result eq 'pass'; last if $result eq 'stop'; # stop if stop is encountered. } =head1 DESCRIPTION This module is designed to pull code counting standards from a formatted XML file and apply pull the rules as needed base on file extention. A dispatch table is returned to the caller so the caller can call the rules directly. Each rule is presented as a key value pair matching the rules name in the XML document. =head1 INTERFACE =head2 hash ref load_standards(file_name_and_path) This function takes the filename path to the standards XML document, reads it, and returns a hash reference. The hash is keyed on file extentions as set forth by code counting standards, where each extention references another hash references of rule names and rule subroutines. =head2 $standard->{$ext}->{$rule_name}->($line) Each rule name references a subroutine that will validate an input line with either a pass, fail, or stop. Pass means that the line passes the rule, fail means it didn't, and stop means that the line has some sort of syntactix end of file marker, like '__END__' or '__DATA__' =head2 hash ref evaluate_standards (XML::Simple structure) This method operates like an interpreter, reading in the XML standards document and building the extention to rules mapping. =head2 hash ref create_rules (XML::Simple rules_structure) This function takes the XML::Simple rules structure and builds a hash reference that maps the rule names defined in the XML document and the actual rules implemented as annonymous subroutines. =head2 sub ref build_rule(pattern_value, operation_type) This function returns a subroutine that implements the pattern matching logic and is capable of returning a pass value or the operation if the pattern matches. =head2 sub ref build_complex_rule(pattern_start_value, pattern_stop_value, operation_type) This function returns a subroutine that implements the pattern matching logic and is capable of returning a pass value or the operation if the pattern matches. It returns a the operation_type until after the stop value is passed. =head1 DIAGNOSTICS The only errors thus far are pass through by XML::Simple. =over =item C<< File not found >> You've mistyped the file name or directory path. =item C<< Other Syntax Errors >> If you XML is not well formed you'll be presented with one or more XML syntax errors. See XML::Simple and XML::Parser for details. =back =head1 CONFIGURATION AND ENVIRONMENT CodeCounter::Standards requires a standards XML document. A standard for Perl is provided in the /conf directory of the CodeCounter distrubution. Modify this one to meet your needs or create you're own. The file can exist anywhere that the program can read from and you can describe. The format goes like this: start-value="^\/\*.+" stop-value="\*\/" op="fail" /> [snip...] =head1 DEPENDENCIES XML::Simple =head1 INCOMPATIBILITIES None reported. =head1 BUGS AND LIMITATIONS No known limitations at this time. Please report any bugs or feature requests to C, or through the web interface at L. =head1 AUTHOR John Fraser C<< >> =head1 LICENCE AND COPYRIGHT Copyright (c) 2005, John Fraser C<< >>. All rights reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See L. =head1 DISCLAIMER OF WARRANTY 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. Metrics-CodeCounter-0.0.1/lib/Metrics/CodeCounter.pm0000644000076500007650000001454610311706617024624 0ustar johnfraserjohnfraser00000000000000package Metrics::CodeCounter; use version; $VERSION = qv('0.0.1'); use warnings; use strict; use Carp; use base qw( Exporter ); use Metrics::CodeCounter::Standards; our @EXPORT = qw( base_count ); sub base_count{ my ($dir, $standards_file) = @_; my %file_counts; my $standards = load_standards($standards_file); directory_and_file_iter($dir, make_code_counter($standards, \%file_counts)); if(wantarray){ return %file_counts; } else{ my $total = 0; foreach my $count (values %file_counts){ $total+=$count; } return $total; } } sub make_code_counter{ my ($standards, $file_counts) = @_; my $ret = sub{ my($file) = @_; my ($count, $ext, $rules, $in); my @exts = ($file =~ /\.([^.]+)$/mg); $ext = $exts[@exts-1]; if (not exists $standards->{$ext}){ warn "Unknown file extention: $ext. Skipping...\n"; $file_counts->{$file} = 0; return; } $rules = $standards->{$ext}; open $in, "<", $file; my @lines = <$in>; foreach my $line (@lines){ my $result; $line =~ s/^\s+//; $line =~ s/\s+$//; for my $rule (keys %{$rules}){ $result = $rules->{$rule}->($line); last if $result ne "pass"; } $count++ if $result eq 'pass'; last if $result eq 'stop'; } close $in; $file_counts->{$file} = $count; }; return $ret; } sub directory_and_file_iter{ my ($dir, $agent) = @_; if (-d $dir){ my @files = glob "$dir/*"; foreach my $file (@files){ directory_and_file_iter( $file, $agent); } } elsif (-f $dir){ $agent->($dir); } else{ carp "$dir is of unknown type $!\n"; } } 1; # Magic true value required at end of module __END__ =head1 NAME CodeCounter - A configurable LOC counter. =head1 VERSION This document describes CodeCounter version 0.0.1 =head1 SYNOPSIS use Metrics::CodeCounter; use Data::Dumper; my %results = base_count('t/test-code', 't/standards.xml'); print Dumper(%results); # prints off file names and LOC counts for each file # --OR-- my $base_count = = base_count('t/test-code', 't/standards.xml'); print "SLOC: $base_count\n"; #prints accumulated LOC for countable source files =head1 DESCRIPTION Provides a basic framework for SLOC counting using standards provided by CodeCounter::Standards. It currently works based on directory walking, working with files that it has extentions for and performing counts. Files having extentions that are unknown aren't counted. =head1 INTERFACE =head2 hash base_count(source_code_directory, standard_file_path) This is the exported interface from this module. It takes a source directory and the path to the standards file. The standards are opened and the rules contained in the standards are applied against all known files in the source_code_directory. =head2 directory_and_file_iter(standard_file_path, callback) A simple directory walker where the callback is passed each file in found during the iteration. =head2 sub make_code_counter(standard_ref, hash_of_files_and_counts_ref) This function creates the actual code counter that is passed as an agent into directory_and_file_iter by the base_count function. The produced function does the real counting work. =head1 DIAGNOSTICS This is still a work in progress. Many possible errors will be passed by the libraries that this module is built upon. =over =item C<< is of unknown type \n >> Not sure when this would happend when counting source code, but... =item C<< "Unknown file extention: . Skipping...\n" >> This error will pop up if a file extention that isn't known is encountered. In many cases this is what you want, in others you'll need to add the extention to an existing standard or create a new one. =back =head1 CONFIGURATION AND ENVIRONMENT CodeCounter requires no configuration files or environment variables. =head1 DEPENDENCIES CodeCounter::Standards =head1 INCOMPATIBILITIES None reported. =head1 BUGS AND LIMITATIONS This module is capable of producing a base count, but cannot compare two existing baselines today. In the next iteration you will be able to compare baselines, which will produce size differences in between versions. For legacy code, this is the only counting method to determine size for projects. Please report any bugs or feature requests to C, or through the web interface at L. =head1 AUTHOR John Fraser C<< >> =head1 LICENCE AND COPYRIGHT Copyright (c) 2005, John Fraser C<< >>. All rights reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See L. =head1 DISCLAIMER OF WARRANTY 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. Metrics-CodeCounter-0.0.1/Makefile.PL0000644000076500007650000000104110311706026021626 0ustar johnfraserjohnfraser00000000000000use strict; use warnings; use ExtUtils::MakeMaker; WriteMakefile( NAME => 'Metrics::CodeCounter', AUTHOR => 'John Fraser ', VERSION_FROM => 'lib/Metrics/CodeCounter.pm', ABSTRACT_FROM => 'lib/Metrics/CodeCounter.pm', PL_FILES => {}, PREREQ_PM => { 'Test::More' => 0, 'version' => 0, }, dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', }, clean => { FILES => 'Metrics-CodeCounter-*' }, ); Metrics-CodeCounter-0.0.1/MANIFEST0000644000076500007650000000126010311707073021013 0ustar johnfraserjohnfraser00000000000000Build.PL Changes MANIFEST META.yml # Will be created by "make dist" Makefile.PL README conf/standards.xml lib/Metrics/CodeCounter.pm lib/Metrics/CodeCounter/Standards.pm t/00.load.t t/01.standards.t t/02.base-count.t t/pod-coverage.t t/pod.t t/test-code/perl/slocrunner.pl t/test-code/perl/stddeviation.pl t/test-code/perl/Utility/Rule.pm t/test-code/perl/Utility/StandardDeviation.pm t/test-code/perl/Utility/SLOCCounter.pm t/test-code/perl/Utility/Utility.pm t/test-code/com/raptnor/io/BasicDirectoryWalkerCallback.java t/test-code/com/raptnor/io/DirectoryWalker.java t/test-code/com/raptnor/io/DirectoryWalkerCallback.java t/test-code/com/raptnor/psp/statistics/StandardDeviation.java Metrics-CodeCounter-0.0.1/README0000644000076500007650000000177210311707203020545 0ustar johnfraserjohnfraser00000000000000Metrics-CodeCounter version 0.0.1 This is the first version of Metrix-CodeCounter, an extensible source lines of code counter. It uses an XML configuration file that keeps track of standards, rules, complex rules, and file extnetions. It is capable of handling multiline comments, and other complex rules that a language may have. Next releases will have increased features, such as an easy to use interface for build scripts and baseline source comparisons to measure added, deleted, and reused LOC. This namespaces will host other SE tools. INSTALLATION To install this module, run the following commands: perl Makefile.PL make make test make install Alternatively, to install with Module::Build, you can use the following commands: perl Build.PL ./Build ./Build test ./Build install DEPENDENCIES None. COPYRIGHT AND LICENCE Copyright (C) 2005, John Fraser This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Metrics-CodeCounter-0.0.1/t/0000755000076500007650000000000010311707566020135 5ustar johnfraserjohnfraser00000000000000Metrics-CodeCounter-0.0.1/t/._.DS_Store0000400000076500000000000000012210311707573020735 0ustar johnfraserwheel00000000000000Mac OS X  2 R@Metrics-CodeCounter-0.0.1/t/.DS_Store0000644000076500007650000001400410311707573021615 0ustar johnfraserjohnfraser00000000000000Bud1‡-codeds test-codedsclbool test-codeicgoblob  @€ @€ @€ @ E‡DSDB ` @€ @€ @Metrics-CodeCounter-0.0.1/t/00.load.t0000644000076500007650000000027510311706026021451 0ustar johnfraserjohnfraser00000000000000use Test::More tests => 2; BEGIN { use_ok( 'Metrics::CodeCounter' ); use_ok( 'Metrics::CodeCounter::Standards' ); } diag( "Testing Metrics::CodeCounter $Metrics::CodeCounter::VERSION" ); Metrics-CodeCounter-0.0.1/t/._01.standards.t0000400000076500000000000000012210311704376021637 0ustar johnfraserwheel00000000000000Mac OS X  2 RSMLdSMULMetrics-CodeCounter-0.0.1/t/01.standards.t0000644000076500007650000000637710311704376022535 0ustar johnfraserjohnfraser00000000000000use strict; use warnings; use Test::More qw(no_plan); my $standards; # for the standards map my $rules; # rule specifics to a given file extention my @extentions = ('pl', 'pm', 't', 'pl2', 'pm2', 't2'); my %lines = ( "# comment rule should cause this to fail" => "fail", "}" => "fail", "sdflklsdf" => "pass", "" => "fail", "__END__" => "stop", "__DATA__" => "stop", ); my @java_lines = ( "package foo;", "/*****************************", " * this shouldn't count", "*****************************/", "", "/*", " * dsafthis shouldn't count", "*/", "// main does something interesting", "class man{", "public static void main(String[] args) {", "System.out.printlin('This should count');", "}", "}", ); my %java_status_for = ( "package foo;" =>"pass", "/*****************************" =>"fail", " * this shouldn't count" =>"fail", "*****************************/" =>"fail", "" =>"fail", "/*" =>"fail", " * dsafthis shouldn't count" =>"fail", "*/" =>"fail", "" =>"fail", "// main does something interesting" =>"fail", "class man{" =>"pass", "public static void main(String[] args) {" =>"pass", "System.out.printlin('This should count');" =>"pass", "}" =>"fail", "}" =>"fail", ); BEGIN { use_ok( 'Metrics::CodeCounter::Standards' ); } ok($standards = load_standards('t/standards.xml'), 'loading standards file'); ok(ref($standards) eq ref({}), 'checking return type is hash ref'); ok(exists $standards->{'pm'} && exists $standards->{'pl'} && exists $standards->{'t'}, 'ensuring extentions exist'); # single line test using Perl for my $extention (@extentions){ $rules = $standards->{$extention}; ok(ref($rules) eq ref({}), 'checking return type is hash ref'); for my $line (keys %lines){ my $result; for my $rule (keys %{$rules}){ $result = $rules->{$rule}->($line); last if $result ne "pass"; } ok($result eq $lines{$line}, "$line for $result"); } } # multi-line test using Java $rules = $standards->{'java'}; ok(ref($rules) eq ref({}), 'checking return type is hash ref'); for my $line (@java_lines){ my $result; for my $rule (keys %{$rules}){ $result = $rules->{$rule}->($line); last if $result ne "pass"; } ok($result eq $java_status_for{$line}, "$line for $result"); }Metrics-CodeCounter-0.0.1/t/._02.base-count.t0000400000076500000000000000012210311704345021711 0ustar johnfraserwheel00000000000000Mac OS X  2 RSMLdSMULMetrics-CodeCounter-0.0.1/t/02.base-count.t0000644000076500007650000000340610311704345022575 0ustar johnfraserjohnfraser00000000000000use strict; use warnings; use Test::More qw(no_plan); use Data::Dumper; my %base_files_and_counts = ( 't/test-code/perl/slocrunner.pl' => 23, 't/test-code/perl/stddeviation.pl' => 12, 't/test-code/perl/Utility/Rule.pm' => 40, 't/test-code/perl/Utility/StandardDeviation.pm' => 22, 't/test-code/perl/Utility/SLOCCounter.pm' => 73, 't/test-code/perl/Utility/Utility.pm' => 4, 't/test-code/com/raptnor/io/BasicDirectoryWalkerCallback.java' =>15, 't/test-code/com/raptnor/io/DirectoryWalker.java' =>26, 't/test-code/com/raptnor/io/DirectoryWalkerCallback.java' =>6, 't/test-code/com/raptnor/psp/statistics/StandardDeviation.java' =>29, ); my %results; my $base_count = 250; my $results_base_count; BEGIN { use_ok( 'Metrics::CodeCounter' ); } ok(%results = base_count('t/test-code', 't/standards.xml'), 'We did receive actual results'); my ($result_count, $base_file_count); $result_count = keys %results; $base_file_count = keys %base_files_and_counts; ok($result_count == $base_file_count, 'File counts are the same'); foreach my $file (keys %base_files_and_counts){ my ($bcount, $rcount); ok( exists $results{$file}, "$file exists in results" ); $bcount = $base_files_and_counts{$file}; $rcount = $results{$file}; ok( $rcount == $bcount, "counts are the correct for $file ($rcount == $bcount)" ) } $results_base_count = base_count('t/test-code', 't/standards.xml'); ok($base_count == $results_base_count, "base counts match ($results_base_count == $base_count)"); # todo: write a test for invalid file extentionsMetrics-CodeCounter-0.0.1/t/pod-coverage.t0000644000076500007650000000025410311706026022664 0ustar johnfraserjohnfraser00000000000000#!perl -T use Test::More; eval "use Test::Pod::Coverage 1.04"; plan skip_all => "Test::Pod::Coverage 1.04 required for testing POD coverage" if $@; all_pod_coverage_ok(); Metrics-CodeCounter-0.0.1/t/pod.t0000644000076500007650000000021410311706026021067 0ustar johnfraserjohnfraser00000000000000#!perl -T use Test::More; eval "use Test::Pod 1.14"; plan skip_all => "Test::Pod 1.14 required for testing POD" if $@; all_pod_files_ok(); Metrics-CodeCounter-0.0.1/t/standards.xml0000644000076500007650000000346710310622273022642 0ustar johnfraserjohnfraser00000000000000 Metrics-CodeCounter-0.0.1/t/test-code/0000755000076500007650000000000010310620063022005 5ustar johnfraserjohnfraser00000000000000Metrics-CodeCounter-0.0.1/t/test-code/._.DS_Store0000400000076500000000000000012210311422670022614 0ustar johnfraserwheel00000000000000Mac OS X  2 R@Metrics-CodeCounter-0.0.1/t/test-code/.DS_Store0000644000076500007650000001400410311422670023474 0ustar johnfraserjohnfraser00000000000000Bud1†clboolcomdsclboolperldsclbool  @€ @€ @€ @ E†DSDB `À @€ @€ @Metrics-CodeCounter-0.0.1/t/test-code/com/0000755000076500007650000000000010244456311022574 5ustar johnfraserjohnfraser00000000000000Metrics-CodeCounter-0.0.1/t/test-code/com/._.DS_Store0000400000076500000000000000012210244456311023376 0ustar johnfraserwheel00000000000000Mac OS X  2 R@Metrics-CodeCounter-0.0.1/t/test-code/com/.DS_Store0000644000076500007650000001400410244456311024256 0ustar johnfraserjohnfraser00000000000000Bud1†nordsclboraptnordsclbool  @€ @€ @€ @ E†DSDB `À @€ @€ @Metrics-CodeCounter-0.0.1/t/test-code/com/raptnor/0000755000076500007650000000000010310620132024245 5ustar johnfraserjohnfraser00000000000000Metrics-CodeCounter-0.0.1/t/test-code/com/raptnor/._.DS_Store0000400000076500000000000000012210310620432025052 0ustar johnfraserwheel00000000000000Mac OS X  2 R@Metrics-CodeCounter-0.0.1/t/test-code/com/raptnor/.DS_Store0000644000076500007650000001400410310620432025732 0ustar johnfraserjohnfraser00000000000000Bud1†boolpiodsclboolpspdsclbool  @€ @€ @€ @ E†DSDB `À @€ @€ @Metrics-CodeCounter-0.0.1/t/test-code/com/raptnor/io/0000755000076500007650000000000010311421607024663 5ustar johnfraserjohnfraser00000000000000Metrics-CodeCounter-0.0.1/t/test-code/com/raptnor/io/._.DS_Store0000400000076500000000000000012210310620114025456 0ustar johnfraserwheel00000000000000Mac OS X  2 R@Metrics-CodeCounter-0.0.1/t/test-code/com/raptnor/io/.DS_Store0000644000076500007650000001400410310620114026336 0ustar johnfraserjohnfraser00000000000000Bud1%  @€ @€ @€ @ E%DSDB`€ @€ @€ @Metrics-CodeCounter-0.0.1/t/test-code/com/raptnor/io/BasicDirectoryWalkerCallback.java0000644000076500007650000000371510311421541033222 0ustar johnfraserjohnfraser00000000000000/* Copyright (c) 2005, John Fraser C<< >>. All rights reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See L. =head1 DISCLAIMER OF WARRANTY 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. */ package com.raptnor.io; import java.io.File; public class BasicDirectoryWalkerCallback implements DirectoryWalkerCallback { long fileCount = 0; long dirCount = 0; public void onFile(File f) { System.out.println("FILE: " + f); fileCount++; } public void onDir(File f) { System.out.println("FILE: " + f); dirCount++; } public void report() { System.out.println("Directory statistics:"); System.out.println("Directory Count: " + dirCount); System.out.println("File Count: " + fileCount); } }Metrics-CodeCounter-0.0.1/t/test-code/com/raptnor/io/DirectoryWalker.java0000644000076500007650000000461710311421561030647 0ustar johnfraserjohnfraser00000000000000/* Copyright (c) 2005, John Fraser C<< >>. All rights reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See L. =head1 DISCLAIMER OF WARRANTY 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. */ package com.raptnor.io; import java.io.File; public class DirectoryWalker { File directory; DirectoryWalkerCallback callback; // TODO: verify that dirToProcess is a directory. public DirectoryWalker(File dirToProcess, DirectoryWalkerCallback callback){ this.callback = callback; directory = dirToProcess; } public DirectoryWalker(File dirToProcess){ this(dirToProcess, new BasicDirectoryWalkerCallback()); } public void walk(){ walkDirectory(directory); callback.report(); } // TODO decide what the else condition void walkDirectory(File dir){ if(dir.isFile()){ callback.onFile(dir); } else if(dir.isDirectory()){ callback.onDir(dir); File[] dirFiles = dir.listFiles(); for(File curFile : dirFiles){ walkDirectory(curFile); } } else{ System.err.println("UNKNOWN: " + dir); } } public static void main(String[] args){ DirectoryWalker d = new DirectoryWalker(new File(args[0])); d.walk(); } }Metrics-CodeCounter-0.0.1/t/test-code/com/raptnor/io/DirectoryWalkerCallback.java0000644000076500007650000000417610311421607032265 0ustar johnfraserjohnfraser00000000000000/* Copyright (c) 2005, John Fraser C<< >>. All rights reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See L. =head1 DISCLAIMER OF WARRANTY 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. */ package com.raptnor.io; import java.io.File; /** * @author johnfraser * @see com.raptnpr.io.DirectoryWalker * * @docRoot * This interface defines the callback interface used by DirectoryWalker. */ public interface DirectoryWalkerCallback { /** * When the directory walker encounters a file, it passes it to this * method. * @param File f */ public void onFile(File f); /** * When the directory walker encounters a directory, it passes it to this * method. * @param File f */ public void onDir(File f); /** * When the directory walker completes its walk, it calls this method to report its * findings, however that may happen. */ public void report(); }Metrics-CodeCounter-0.0.1/t/test-code/com/raptnor/psp/0000755000076500007650000000000010244456316025070 5ustar johnfraserjohnfraser00000000000000Metrics-CodeCounter-0.0.1/t/test-code/com/raptnor/psp/._.DS_Store0000400000076500000000000000012210244456316025672 0ustar johnfraserwheel00000000000000Mac OS X  2 R@Metrics-CodeCounter-0.0.1/t/test-code/com/raptnor/psp/.DS_Store0000644000076500007650000001400410244456316026552 0ustar johnfraserjohnfraser00000000000000Bud1†istics statisticsdsclbool  @€ @€ @€ @ E†DSDB `À @€ @€ @Metrics-CodeCounter-0.0.1/t/test-code/com/raptnor/psp/statistics/0000755000076500007650000000000010311421524027246 5ustar johnfraserjohnfraser00000000000000Metrics-CodeCounter-0.0.1/t/test-code/com/raptnor/psp/statistics/._.DS_Store0000400000076500000000000000012210310620451030047 0ustar johnfraserwheel00000000000000Mac OS X  2 R@Metrics-CodeCounter-0.0.1/t/test-code/com/raptnor/psp/statistics/.DS_Store0000644000076500007650000001400410310620451030727 0ustar johnfraserjohnfraser00000000000000Bud1%  @€ @€ @€ @ E%DSDB`€ @€ @€ @Metrics-CodeCounter-0.0.1/t/test-code/com/raptnor/psp/statistics/StandardDeviation.java0000644000076500007650000000540110311421524033514 0ustar johnfraserjohnfraser00000000000000/* Copyright (c) 2005, John Fraser C<< >>. All rights reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See L. =head1 DISCLAIMER OF WARRANTY 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. */ package com.raptnor.psp.statistics; /** * @author johnfraser * **/ public class StandardDeviation { public static double compute(double[] values){ return Math.sqrt(variance(values)); } public static double mean(double[] values){ long sum = 0; int count = values.length; for(int i=0;icount(); } elsif($ARGV[0] eq '-c'){ my $new = new Utility::SLOCCounter($ARGV[1]); my $old = new Utility::SLOCCounter($ARGV[2]); my ($deleted, $added, $reused) = $new->compare($old); my $base = $new->count(); print "SLOC Compared:\n"; print "\tBase:\t$base\n"; print "\tAdded:\t$added\n"; print "\tDeleted:\t$deleted\n"; print "\tReused:\t$reused\n"; } else{ print "Help:\nslocrunner.pl - this is a simple script to perform base counts on one file,\n"; print "\tcompares one and new files for differences\n\n"; print "Usage: perl slocrunner.pl -(bc) [oldfile]\n"; print "Examples:\n"; print "\tCalculate base only: slocrunner.pl -b somefile.pl\n"; print "\tCalculate difference: slocrunner.pl -c newfile.pl oldfile.pl\n"; } __END__ =pod =head1 NAME slocrunner.pl =head1 SYNOPSIS Base only: slocrunner.pl -b someperlfile.pm Compare: slocrunner.pl -c newfile.pm oldfile.pm =head1 SUMMARY slocrunner is a dirver program for the SLOCCounter program. It supports both calculating base for one Perl source file or calculating added, deleted, reused, and base for two perl source files. This of course assumes that you have access to both files, and you haven't overwritten the old with the new. If you haven't done so, please put some type of CM process in place. CVS will work, or use local directories if you happen to be at home and alone. =head1 AUTHOR johnfraser =head1 COPYRIGHT AND LICENSE Copyright (c) 2005, John Fraser C<< >>. All rights reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See L. =head1 DISCLAIMER OF WARRANTY 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. =cutMetrics-CodeCounter-0.0.1/t/test-code/perl/stddeviation.pl0000644000076500007650000000367110311421731026012 0ustar johnfraserjohnfraser00000000000000use strict; use warnings; use Utility::StandardDeviation; my @test1 = (160,591,114,229,230,270,128,1657,624,1503); my @test2 = (186,699,132,272,291,331,199,1890,788,1601); my @test3 = (15.0,69.9,6.5,22.4,28.4,65.9,19.4,198.7,38.8,138.2); my $sd1 = new Utility::StandardDeviation(@test1); my $sd2 = new Utility::StandardDeviation(@test2); my $sd3 = new Utility::StandardDeviation(@test3); print $sd1->compute(), "\n"; print $sd2->compute(), "\n"; print $sd3->compute(), "\n"; __END__ =pod Copyright (c) 2005, John Fraser C<< >>. All rights reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See L. =head1 DISCLAIMER OF WARRANTY 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. =cutMetrics-CodeCounter-0.0.1/t/test-code/perl/Utility/0000755000076500007650000000000010311422212024407 5ustar johnfraserjohnfraser00000000000000Metrics-CodeCounter-0.0.1/t/test-code/perl/Utility/._.DS_Store0000400000076500000000000000012210307111561025220 0ustar johnfraserwheel00000000000000Mac OS X  2 R@Metrics-CodeCounter-0.0.1/t/test-code/perl/Utility/.DS_Store0000644000076500007650000001400410307111561026100 0ustar johnfraserjohnfraser00000000000000Bud1%  @€ @€ @€ @ E%DSDB`€ @€ @€ @Metrics-CodeCounter-0.0.1/t/test-code/perl/Utility/Rule.pm0000644000076500007650000000733210311421764025674 0ustar johnfraserjohnfraser00000000000000############################################ # Rule is a base class for a chain of # responsibility pattern for SLOC counting # and hopefully a building spot for more # complex SLOC counting. # See POD for more details ############################################ package Utility::Rule; use strict; use warnings; sub new{ my($class) = @_; my $struct = { PASS => 1, FAIL => 0, STOP => -1, }; return bless $struct, $class; } sub appy{ my($self) = @_; die "Rule::Apply is abstract"; } package Utility::Rule::CommentRule; use base ('Utility::Rule'); sub apply{ my ($self, $line) = @_; return $self->{FAIL} if $line =~ /^#/; return $self->{PASS}; } package Utility::Rule::BracketRule; use base ('Utility::Rule'); sub apply{ my ($self, $line) = @_; return $self->{FAIL} if $line eq '}'; return $self->{PASS}; } package Utility::Rule::WhitespaceRule; use base ('Utility::Rule'); sub apply{ my ($self, $line) = @_; return $self->{FAIL} unless $line; return $self->{PASS}; } package Utility::Rule::EndAndDataRule; use base ('Utility::Rule'); sub apply{ my ($self, $line) = @_; return $self->{STOP} if (($line eq '__END__') || ($line eq '__DATA__')); return $self->{PASS}; } 1; __END__ =pod =head1 NAME Rule.pm =head1 SUMMARY Rule is a base class for a pattern called Chain of Responsibility. Each rule determines if the line meets one of three conditions. It test whether it passed, failed, or if the counter should be stopped. =head2 Rule =head3 new Creation method. No parameters. There are three properties that should be used as return values. $self->{PASS} $self->{FAIL} $self->{STOP} =head3 apply Takes a string, and determines if the string counts. If the string passes the rules test, return PASS, else return FAIL. If the rule determines that the counter should stop, return STOP. It may also do more complicated stuff internally if needed. =head2 WhitespaceRule Returns pass unless the line is whitespace. =head2 EndAndDataRule Returns pass unless it finds and '__END__' or '__DATA__' section. If it does find either one, it returns a stop. =head2 BracketRule Returns pass unless the line is a '}'. =head2 CommentRule Returns pass unless the line begins with a '#'. =head1 AUTHOR johnfraser =head1 COPYRIGHT AND LICENSE Copyright (c) 2005, John Fraser C<< >>. All rights reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See L. =head1 DISCLAIMER OF WARRANTY 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. =cutMetrics-CodeCounter-0.0.1/t/test-code/perl/Utility/._SLOCCounter.pm0000400000076500000000000000012210311422041026164 0ustar johnfraserwheel00000000000000Mac OS X  2 RTEXTMetrics-CodeCounter-0.0.1/t/test-code/perl/Utility/SLOCCounter.pm0000644000076500007650000001204410311422041027046 0ustar johnfraserjohnfraser00000000000000################################################################################ # SLOCCounter performs base SLOC counts, and compares itself against other # SLOCCounter objects. # Change Log: #------------------------------------------------------------------------------- # JRF JAN 27 2005 EST Created # JRF JAN 28 2005 EST Updated for comparing against another SLOCCounter #------------------------------------------------------------------------------- # See POD for more details ################################################################################ package Utility::SLOCCounter; use strict; use warnings; use Utility::Rule; sub new{ my ($class, $file_name) = @_; open (IN, "<$file_name") or die "SLOCCounter can't open filename:\n$!"; my @lines = ; my $struct = { verbose => 1, lines => \@lines, cleaned_lines => undef, counted_lines => undef, rules => [ new Utility::Rule::WhitespaceRule(), new Utility::Rule::CommentRule(), new Utility::Rule::BracketRule(), new Utility::Rule::EndAndDataRule() ] }; my $self = bless $struct, $class; $self->clean_lines(); $self->count(); return $self; } sub count{ my ($self) = @_; my $count = 0; my @counted; LINE_LOOP: foreach my $line (@{$self->{cleaned_lines}}){ foreach my $rule (@{$self->{rules}}){ if ($rule->apply($line) == $rule->{FAIL}){ next LINE_LOOP; } elsif($rule->apply($line) == $rule->{STOP}){ last LINE_LOOP; } } $count++; push @counted, $line; } $self->{counted_lines} = \@counted; return $count; } sub clean_lines{ my($self) = @_; my @cleaned; foreach my $line (@{$self->{lines}}){ chomp($line); $line =~ s/^\s+//; $line =~ s/\s+$//; push (@cleaned, $line) if $line; } $self->{cleaned_lines} = \@cleaned; } sub compare{ my($self, $old_sloc) = @_; my @new_lines = @{$self->{counted_lines}}; my @old_lines = @{$old_sloc->{counted_lines}}; my $deleted = $self->_generic_compare(\@old_lines, \@new_lines); my $added = $self->_generic_compare(\@new_lines, \@old_lines); return ($deleted, $added, $old_sloc->count() - $deleted) } sub _generic_compare{ my ($self, $comparethis, $tothis) = @_; my @compare = @{$comparethis}; my @to = @{$tothis}; my $found = -1; my $base_count = @compare; my $count = 0; for(my $i=0; $i< @compare; $i++){ for(my $j=0; $j< @to; $j++){ if (($to[$j]) && ($compare[$i] eq $to[$j])){ $found = $j; print "MATCH: " . $compare[$i] . " === " . $to[$j] . "\n" if $self->{verbose}; last; } } if($found > -1){ delete $to[$found]; $count++; $found = -1; } } return $base_count - $count; } 1; __END__ =pod =head1 NAME SLOCCounter.pm =head1 SYNOPSIS my $sloc = new Utility::SLOCCounter("some_file.pl"); $sloc->count(); # returns the Source Lines of Code =head1 SUMMARY SLOCCounter is a source lines of code counter primarily designed for perl, although it is not limited to Perl. It uses a simple Rule based mechanism to determine if a line in a file counts. See Utility::Rule for more information on rules. =head2 Utility::SLOCCounter(*) Takes a file handle for source code. Opens file handle and converts contents to lines of code. Creates Perl rules for counting use. =head3 count Applys all rules to each line of code. If a rule passes, then the count gets incremented. If a rule declares a stop, then the couting stops. =head3 clean_lines Trips leading and trailling space off of the lines. =head3 compare Takes another SLCO which it treats as old. Returns a list in the form of (deleted, added, reused) =head1 AUTHOR johnfraser =head1 COPYRIGHT AND LICENSE Copyright (c) 2005, John Fraser C<< >>. All rights reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See L. =head1 DISCLAIMER OF WARRANTY 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. =cutMetrics-CodeCounter-0.0.1/t/test-code/perl/Utility/StandardDeviation.pm0000644000076500007650000000622110311422212030351 0ustar johnfraserjohnfraser00000000000000############################################# # Class to handle standard deviations for # PSP processes # See POD for more details ############################################# package Utility::StandardDeviation; sub new{ my ($class, @list) = @_; return bless \@list, $class; } sub compute{ my $self = shift; sqrt($self->_variance()); } sub _mean{ my $self = shift; my $sum = 0; my $count = @{$self}; foreach my $num (@{$self}){ $sum += $num; } return $sum / $count; } sub _variance{ my $self = shift; my ($mean, $sum) = ($self->_mean(), 0); my $count = @{$self}; foreach my $num (@{$self}){ $sum += (($num - $mean) ** 2); } return $sum / ($count-1); } 1; __END__ =pod =head1 NAME Utility::StandardDeviation =head1 SYNOPSIS use Utility::StandardDeviation; my @test1 = (160,591,114,229,230,270,128,1657,624,1503); my $sd1 = new Utility::StandardDeviation(@test1); print $sd1->compute(), "\n"; # prints 572.027 (~) =head1 SUMMARY This package provides a very simple method to compute standard deviations. It is intended to be used with the Personal Software Process, but it may have other utilities for you. =head2 Utility::StandardDeviation This is a Perl class blessed from an array reference passed in on creation. =head3 Utility::StandardDeviation::new(@) Creation method. Takes array to compute as argument. =head3 Utility::StandardDeviation::_mean() Calculates the mean of the list. Mean is a fancy word for array. =head3 Utility::StandardDeviation::_variance() Calculates the variance of the list. =head3 Utility::StandardDeviation::compute() Performs a sqrt on the variance of the classes list value. =head1 AUTHOR John Fraser =head1 COPYRIGHT AND LICENSE Copyright (c) 2005, John Fraser C<< >>. All rights reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See L. =head1 DISCLAIMER OF WARRANTY 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. =cutMetrics-CodeCounter-0.0.1/t/test-code/perl/Utility/Utility.pm0000644000076500007650000000314410311422020026407 0ustar johnfraserjohnfraser00000000000000############################################## # a general utilities package for PSP work. package Utility; use strict; use warnings; 1; __END__ =pod Copyright (c) 2005, John Fraser C<< >>. All rights reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See L. =head1 DISCLAIMER OF WARRANTY 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. =cut