File: countperl

package info (click to toggle)
libperl-metrics-simple-perl 1.0.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 316 kB
  • sloc: perl: 1,472; makefile: 7
file content (275 lines) | stat: -rw-r--r-- 6,483 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
#!/usr/bin/env perl

use strict;
use warnings;

use Carp qw(croak);
use Getopt::Long;
use Perl::Metrics::Simple 0.13;
use Perl::Metrics::Simple::Output::HTML;
use Perl::Metrics::Simple::Output::JSON;
use Perl::Metrics::Simple::Output::PlainText;
use Pod::Usage qw(pod2usage);

our $VERSION = 'v1.0.3';

exit main() if not caller;

#-------------------------------------------------------------------------------

sub main {
    my ( $options, @files ) = parse_opts(@ARGV);

    if ( $options->{'help'} ) {
        pod2usage( -verbose => 2, -exitval => 1 );    # exits program
    }

    if ( my $modifiers = $options->{'method-modifiers'} ) {
        push @Perl::Metrics::Simple::Analysis::File::METHOD_MODIFIERS,
            split /,/sxm, $modifiers;
    }

    my $analysis = Perl::Metrics::Simple->new()->analyze_files(@files);

    if ( $options->{'html'} ) {
        my $html = Perl::Metrics::Simple::Output::HTML->new($analysis);
        print $html->make_report() or croak 'Failed to print!';
    }
    elsif ( $options->{'json'} ) {
        my $json = Perl::Metrics::Simple::Output::JSON->new($analysis);
        print $json->make_report() or croak 'Failed to print!';
    }
    else {
        my $plain = Perl::Metrics::Simple::Output::PlainText->new($analysis);
        print $plain->make_report() or croak 'Failed to print!';
    }

    return 0;
}

sub parse_opts {
    my (@command_line_arguments) = @_;

    if ( !@command_line_arguments ) {
        pod2usage(
            -msg     => "Missing required argument(s).\n",
            -exitval => 1,
            -verbose => 1,
        );    # exits program
    }

    my %options;

    my $parsed_ok = Getopt::Long::GetOptionsFromArray(
        \@command_line_arguments,
        \%options,
        'html',
        'json',
        'method-modifiers:s',
    );

    if ( !$parsed_ok ) {
        pod2usage(
            -msg     => "Failed to parse command line.\n",
            -exitval => 1,
            -verbose => 1,
        );    # exits program
    }

    return ( \%options, @command_line_arguments );
}

__END__

=head1 NAME

countperl - count lines, packages, subs, and complexity of Perl files.

=head1 USAGE

B<countperl> F<FILE_OR_DIRECTORY> [F<FILE_OR_DIRECTORY> ...] [--html] [--help] [--method-modifiers=a,b,c]

=head1 REQUIRED ARGUMENTS

At least one file or directory path must be supplied.

=head1 OPTIONS

=over 4

=item --help

Prints documentation to STDERR.

=item --html

Produces HTML output instead of the plain-text default.

=item --json

Produces JSON output instead of the plain-text default.

=item --method-modifiers=a,b,c

A comma-separated list of method modifiers to be recognised, see
L<Moose::Manual::MethodModifiers> for details. If unspecified, the
default list is before,after,around.

=back

=head1 CONFIGURATION

N/A. Currently no support for any configuration files.

=head1 EXIT STATUS

Exits zero on success, non-zero on failure.

=head1 DESCRIPTION

F<countperl> uses B<Perl::Metrics::Simple> to examines the named files and
recursivesly searches named directories for Perl files.


Perl files are identified by B<Perl::Metrics::Simple-E<gt>is_perl_file>. Basically
if the file ends in C<.pl>, C<.pm>, or C<.t> or has what appears to be a perl
I<shebang> line.

F<countperl> produces a report on F<STDOUT> of counts of total lines,
packages, subroutines/methods,
the minimum, maximum, mean, standard deviation, and median size and
mccabe_complexity (cyclomatic complexity) of subroutines and
the 'main' portion of each file (everything not in a subroutine.)

=head2 Output Format

Line counts do not include comments nor pod.

The current output format is human-readable text:

    Perl files found:                3

    Counts
    ------
    total code lines:       856
    lines of non-sub code:  450
    packages found:           3
    subs/methods:            42

    Subroutine/Method Size
    ----------------------
    min:                  3 lines
    max:                  32 lines
    mean:                 9.67 lines
    std. deviation:       7.03
    median:               7.50

    McCabe Complexity
    -----------------
    Code not in any subroutine::
    min:                  1
    max                   1
    mean:                 1.00
    std. deviation:       0.00
    median:               1.00

    Subroutines/Methods:
    min:                  1
    max:                  5
    avg:                  1.00
    std. deviation:       1.36
    median:               1.00

    Tab-delimited list of subroutines, with most complex at top
    -----------------------------------------------------------
    complexity      sub     path    size
    5       is_perl_file    lib/Perl/Metrics/Simple.pm      11
    5       _has_perl_shebang       lib/Perl/Metrics/Simple.pm      13
    5       _init   lib/Perl/Metrics/Simple/Analysis/File.pm        30
    4       find_files      lib/Perl/Metrics/Simple.pm      11
    4       new     lib/Perl/Metrics/Simple/Analysis.pm     10
    4       is_ref  lib/Perl/Metrics/Simple/Analysis.pm     8

With --html switch output format is HTML.

=head1 VERSION

This is version 0.031 of F<countperl>.

=head1 DIAGNOSTICS

Prints usage message to STDERR if required arguments are not provided.

=head1 INCOMPATIBILITIES

None known.

=head1 BUGS AND LIMITATIONS

=head2 Bugs
No bugs reported yet :-)
See: http://rt.cpan.org/NoAuth/Bugs.html?Dist=Perl-Metrics-Simple

=head2 Limitations

=over 4

=item Does not accept input from STDIN.

=item No machine-readable report format available (e.g. XML, tab-delimited)

=back

=head1 SUPPORT

Via CPAN:

=head2 Disussion Forum

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

=head2 Bug Reports

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

=head1 DEPENDENCIES

=over 4

=item L<Perl::Metrics::Simple|Perl::Metrics::Simple> 0.13 (which depends upon L<PPI|PPI>.)

=item L<Pod::Usage|Pod::Usage>

=back

=head1 SEE ALSO

=over 4

=item L<PPI|PPI>

=item L<Perl::Critic|Perl::Critic>

=item L<Perl::Metrics|Perl::Metrics>

=item http://en.wikipedia.org/wiki/Cyclomatic_complexity

=back

=head1 AUTHOR

    Matisse Enzer
    CPAN ID: MATISSE
    Eigenstate Consulting, LLC
    matisse@eigenstate.net
    http://www.eigenstate.net/

=head1 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.

=cut