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
  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 norm,ailizes line endings to newlines so CR/LF, CR and LF all come out the same.

lines

main_stats

measure_complexity

Takes a PPI element and measures the Mccabe Complexity (aka Cyclomatic Complexity) of the code. The complexity count is 1 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

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.