File Coverage: lib/Code/Statistics.pm

# File Coverage

File: | lib/Code/Statistics.pm
Coverage: | 100.0%

line | stmt | bran | cond | sub | pod | time | code
--- | --- | --- | --- | --- | --- | --- | ---
1 | 1 1 1 |  |  | 1 |  | 0 0 0 | use strict;
2 | 1 1 1 |  |  | 1 |  | 0 0 0 | use warnings;
3 |
4 |  |  |  |  |  |  | package Code::Statistics;
5 |
6 |  |  |  |  |  |  | # ABSTRACT: collects and reports statistics on perl code
7 |
8 - 19 |  |
    =head1 SYNOPSIS

    On a terminal:

        # collect statistics on the current directory and sub-directories,
        # then store results in codestat.out as json
        codestat collect

        # compile a report from codestat.out and print to the terminal
        codestat report

    =cut
20 |
21 - 48 |  |
    =head1 DESCRIPTION

    This is a framework to collect various metrics on a codebase and report them
    in a summarized manner. It is meant to be as extensible as possible.

    The current collection workflows are as follow:

    =head2 Collection

    All files in the search path are collected.

    Target constructs as defined by modules living under Code::Statistics::Target:: are collected for all files.

    Metrics as defined by modules living under Code::Statistics::Metric:: are collected for all targets.

    All data is dumped as json to C<codestat.out>.

    =head2 Reporting

    Data from the local C<codestat.out> is read.

    Data is grouped by target and for each target type the following is printed:

    Averages of all non-location metrics.

    Tables with the top ten and bottom ten for each significant metric.

    =cut
49 |
50 | 1 1 1 |  |  | 1 |  | 0 0 0 | use Code::Statistics::Config;
51 | 1 1 1 |  |  | 1 |  | 0 0 0 | use Code::Statistics::Collector;
52 | 1 1 1 |  |  | 1 |  | 0 0 0 | use Code::Statistics::Reporter;
53 |
54 | 1 1 1 |  |  | 1 |  | 0 0 0 | use Moose;
55 | 1 1 1 |  |  | 1 |  | 0 0 0 | use MooseX::HasDefaults::RO;
56 | 1 1 1 |  |  | 1 |  | 0 0 0 | use Code::Statistics::SlurpyConstructor;
57 |
58 |  |  |  |  |  |  | has config_args => (
59 |  |  |  |  |  |  | is => 'ro',
60 |  |  |  |  |  |  | slurpy => 1,
61 |  |  |  |  |  |  | );
62 |
63 |  |  |  |  |  |  | sub _command_config {
64 | 3 |  |  | 3 |  | 0 | my ( $self ) = @_;
65 | 3 3 |  |  |  |  | 0 0 | my $config = Code::Statistics::Config->new( %{ $self->config_args } )->assemble;
66 | 3 |  |  |  |  | 0 | return $config;
67 |  |  |  |  |  |  | }
68 |
69 - 75 |  |
    =head1 SUBROUTINES/METHODS

    This module acts mostly as a dispatcher and collects configuration data,
    then forwards it to actual action modules. These are the methods it
    currently provides.

    =cut
76 |
77 - 81 |  |
    =head2 collect

        Dispatches configuration to the statistics collector module.

    =cut
82 |
83 |  |  |  |  |  |  | sub collect {
84 | 2 |  |  | 2 |  | 0 | my ( $self ) = @_;
85 | 2 |  |  |  |  | 0 | return Code::Statistics::Collector->new( $self->_command_config )->collect;
86 |  |  |  |  |  |  | }
87 |
88 - 92 |  |
    =head2 report

        Dispatches configuration to the statistics reporter module.

    =cut
93 |
94 |  |  |  |  |  |  | sub report {
95 | 1 |  |  | 1 |  | 0 | my ( $self ) = @_;
96 | 1 |  |  |  |  | 0 | return Code::Statistics::Reporter->new( $self->_command_config )->report;
97 |  |  |  |  |  |  | }
98 |
99 - 109 |  |
    =head1 TODO

    Possibly elevate metrics to objects to allow parametrized metrics during
    collection. Not sure if i want this or whether making more generic metrics is a
    better idea. http://gist.github.com/549132

    =head1 SEE ALSO

    PPI::Tester

    =cut
110 |
111 |  |  |  |  |  |  | 1;