NAME

Perl::Metrics::Simple::Analysis::File - Methods analyzing a single file.

SYNOPSIS

use Perl::Metrics::Simple::Analysis::File;
my $object = Perl::Metrics::Simple::Analysis::File->new(file => 'path/to/file');

VERSION

This is VERSION 0.02.

DESCRIPTION

A Perl::Metrics::Simple::Analysis::File object is created by Perl::Metrics::Simple for each file analyzed. These objects are aggregated into a Perl::Metrics::Simple::Analysis object by Perl::Metrics::Simple.

In general you will not use this calss directly, instead you will use Perl::Metrics::Simple, but there's no harm in exposing the various methods this class provides.

CLASS METHODS

new

Takes named parameters, current only the path parameter is recognized:

my $file_results = BPerl::Metrics::Simple::Analysis::File->new( path => $path );

Returns a new Perl::Metrics::Simple::Analysis::File object which has been populated with the results of analyzing the file at path.

Throws an exception if the path is missing or unreadable.

OBJECT METHODS

Call on an object.

all_counts

Convenience method. Takes no arguments and returns a hashref of all counts: { path => $self->path, lines => $self->lines, main_stats => $self->main_stats, subs => $self->subs, packages => $self->packages, }

analyze_main

Takes a PPI document and an arrayref of PPI::Statement::Sub objects and returns a hashref with information about the 'main' (non-subroutine) portions of the document:

{
  lines             => $lines,      # Line count outside subs. Skips comments and pod.
  mccabe_complexity => $complexity, # Cyclomatic complexity of all non-sub areas
};

get_node_length

Takes a PPI node and returns a count of the newlines it contains. PPI normalizes line endings to newlines so CR/LF, CR and LF all come out the same. The line counts reported by the various methods in this class all exclude blank lines, comment lines and pod (the PPI document is pruned before counting.)

lines

Total non-blank, non-comment/pod lines.

main_stats

Returns the hashref generated by analyze_main.

measure_complexity

Takes a PPI element and measures the McCabe Complexity (aka Cyclomatic Complexity) of the code. McCabe Complexity is basically a count of how many paths there are through the code. We use a simplified method for count this, which ignores things like the possibility that a 'use' statement with throw an exception.

The complexity count is 1 for any non-comment/pod code plus 1 for each logic keyword or operator:

Logic operators:

! && || ||= &&= or and xor not ? <<= >>=

Logic keywords:

for foreach goto if else elsif last next unless until while

Example of complexity 1:

# Only one  path through the code.
use Foo;
print "Hello world.\n";
exit;

Example of complexity 2:

# There are two possible paths through this code:
if ( $a ) {
}

packages

Arrayref of unique packages found in the file.

path

Path to the file.

subs

Count of subroutines found.

STATIC PACKAGE SUBROUTINES

Utility subs used internally, but not harm in exposing them for now.

hashify

%hash = Perl::Metrics::Simple::Analysis::File::hashify(@list);

Takes an array and returns a hash using the array values as the keys and with the values all set to 1.

is_hash_key

$boolean = Perl::Metrics::Simple::Analysis::File::is_hash_key($ppi_element);

Takes a PPI::Element and returns true if the element is a hash key, for example foo and bar are hash keys in the following:

 { foo => 123, bar => $a }

Returns true if Copied and somehwat simplified from http://search.cpan.org/src/THALJEF/Perl-Critic-0.19/lib/Perl/Critic/Utils.pm See Perl::Critic::Utils.

BUGS AND LIMITATIONS

None reported yet ;-)

DEPENDENCIES

Readonly
Statistics::Basic

SUPPORT

Via CPAN:

Disussion Forum

http://www.cpanforum.com/dist/Perl-Metrics-Simple

Bug Reports

http://rt.cpan.org/NoAuth/Bugs.html?Dist=Perl-Metrics-Simple

AUTHOR

Matisse Enzer
CPAN ID: MATISSE
Eigenstate Consulting, LLC
matisse@eigenstate.net
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.