line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perl::Metrics::Simple::Output::PlainText; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
786
|
use strict; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
33
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
459
|
use parent qw(Perl::Metrics::Simple::Output); |
|
1
|
|
|
|
|
310
|
|
|
1
|
|
|
|
|
6
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
593
|
use Readonly 1.03; |
|
1
|
|
|
|
|
4101
|
|
|
1
|
|
|
|
|
1380
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = 'v1.0.3'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Readonly my $MAX_PLAINTEXT_LABEL_LENGTH => 25; |
13
|
|
|
|
|
|
|
Readonly my $EMPTY_STRING => q{}; |
14
|
|
|
|
|
|
|
Readonly my $ONE_SPACE => q{ }; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub make_report { |
17
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
18
|
|
|
|
|
|
|
|
19
|
0
|
|
|
|
|
|
my $report = 'Perl files found: ' . $self->analysis()->file_count() . "\n\n"; |
20
|
0
|
|
|
|
|
|
$report .= $self->make_counts(); |
21
|
0
|
|
|
|
|
|
$report .= $self->make_subroutine_size(); |
22
|
0
|
|
|
|
|
|
$report .= $self->make_code_complexity(); |
23
|
0
|
|
|
|
|
|
$report .= $self->make_list_of_subs(); |
24
|
0
|
|
|
|
|
|
return $report; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub make_counts { |
28
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
29
|
|
|
|
|
|
|
|
30
|
0
|
|
|
|
|
|
my $counts = _make_headline('Counts'); |
31
|
0
|
|
|
|
|
|
$counts .= _make_line( 'total code lines', $self->analysis()->lines() ); |
32
|
|
|
|
|
|
|
$counts .= _make_line( |
33
|
|
|
|
|
|
|
'lines of non-sub code', |
34
|
|
|
|
|
|
|
$self->analysis()->main_stats()->{lines} |
35
|
0
|
|
|
|
|
|
); |
36
|
0
|
|
|
|
|
|
$counts .= _make_line( 'packages found', $self->analysis()->package_count() ); |
37
|
0
|
|
|
|
|
|
$counts .= _make_line( 'subs/methods', $self->analysis()->sub_count() ); |
38
|
0
|
|
|
|
|
|
$counts .= "\n\n"; |
39
|
0
|
|
|
|
|
|
return $counts; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub make_subroutine_size { |
43
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
my $subroutine_size = _make_headline('Subroutine/Method Size'); |
46
|
|
|
|
|
|
|
$subroutine_size .= _make_line( |
47
|
|
|
|
|
|
|
'min', |
48
|
|
|
|
|
|
|
$self->analysis()->summary_stats()->{sub_length}->{min} |
49
|
0
|
|
|
|
|
|
); |
50
|
|
|
|
|
|
|
$subroutine_size .= _make_line( |
51
|
|
|
|
|
|
|
'max', |
52
|
|
|
|
|
|
|
$self->analysis()->summary_stats()->{sub_length}->{max} |
53
|
0
|
|
|
|
|
|
); |
54
|
|
|
|
|
|
|
$subroutine_size .= _make_line( |
55
|
|
|
|
|
|
|
'mean', |
56
|
|
|
|
|
|
|
$self->analysis()->summary_stats()->{sub_length}->{mean} |
57
|
0
|
|
|
|
|
|
); |
58
|
|
|
|
|
|
|
$subroutine_size .= _make_line( |
59
|
|
|
|
|
|
|
'std. deviation', |
60
|
|
|
|
|
|
|
$self->analysis()->summary_stats()->{sub_length}->{standard_deviation} |
61
|
0
|
|
|
|
|
|
); |
62
|
|
|
|
|
|
|
$subroutine_size .= _make_line( |
63
|
|
|
|
|
|
|
'median', |
64
|
|
|
|
|
|
|
$self->analysis()->summary_stats()->{sub_length}->{median} |
65
|
0
|
|
|
|
|
|
); |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
$subroutine_size .= "\n\n"; |
68
|
0
|
|
|
|
|
|
return $subroutine_size; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub make_code_complexity { |
72
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
73
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
my $code_complexity = _make_headline('McCabe Complexity'); |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
$code_complexity .= $self->make_complexity_section( |
77
|
|
|
|
|
|
|
'Code not in any subroutine', |
78
|
|
|
|
|
|
|
'main_complexity' |
79
|
|
|
|
|
|
|
); |
80
|
0
|
|
|
|
|
|
$code_complexity .= "\n"; |
81
|
0
|
|
|
|
|
|
$code_complexity .= $self->make_complexity_section( |
82
|
|
|
|
|
|
|
'Subroutines/Methods', |
83
|
|
|
|
|
|
|
'sub_complexity' |
84
|
|
|
|
|
|
|
); |
85
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
$code_complexity .= "\n\n"; |
87
|
0
|
|
|
|
|
|
return $code_complexity; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub make_complexity_section { |
91
|
0
|
|
|
0
|
0
|
|
my ( $self, $section, $key ) = @_; |
92
|
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
|
my $complexity_section = $section . "\n"; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
$complexity_section |
96
|
0
|
|
|
|
|
|
.= _make_line( 'min', $self->analysis()->summary_stats()->{$key}->{min} ); |
97
|
|
|
|
|
|
|
$complexity_section |
98
|
0
|
|
|
|
|
|
.= _make_line( 'max', $self->analysis()->summary_stats()->{$key}->{max} ); |
99
|
|
|
|
|
|
|
$complexity_section .= _make_line( |
100
|
|
|
|
|
|
|
'mean', |
101
|
|
|
|
|
|
|
$self->analysis()->summary_stats()->{$key}->{mean} |
102
|
0
|
|
|
|
|
|
); |
103
|
|
|
|
|
|
|
$complexity_section .= _make_line( |
104
|
|
|
|
|
|
|
'std. deviation', |
105
|
|
|
|
|
|
|
$self->analysis()->summary_stats()->{$key}->{standard_deviation} |
106
|
0
|
|
|
|
|
|
); |
107
|
|
|
|
|
|
|
$complexity_section .= _make_line( |
108
|
|
|
|
|
|
|
'median', |
109
|
|
|
|
|
|
|
$self->analysis()->summary_stats()->{$key}->{median} |
110
|
0
|
|
|
|
|
|
); |
111
|
0
|
|
|
|
|
|
return $complexity_section; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub make_list_of_subs { |
115
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
116
|
|
|
|
|
|
|
|
117
|
0
|
|
|
|
|
|
my ( $main_from_each_file, $sorted_all_subs ) = @{ $self->SUPER::make_list_of_subs() }; |
|
0
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
|
119
|
0
|
|
|
|
|
|
my $column_widths = _get_column_widths($main_from_each_file); |
120
|
|
|
|
|
|
|
|
121
|
0
|
|
|
|
|
|
my $list_of_subs = _make_headline('List of subroutines, with most complex at top'); |
122
|
|
|
|
|
|
|
|
123
|
0
|
|
|
|
|
|
$list_of_subs .= _make_column( 'complexity', $column_widths->{mccabe_complexity} ); |
124
|
0
|
|
|
|
|
|
$list_of_subs .= _make_column( 'sub', $column_widths->{name} ); |
125
|
0
|
|
|
|
|
|
$list_of_subs .= _make_column( 'path', $column_widths->{path} ); |
126
|
0
|
|
|
|
|
|
$list_of_subs .= _make_column( 'size', $column_widths->{lines} ); |
127
|
0
|
|
|
|
|
|
$list_of_subs .= "\n"; |
128
|
|
|
|
|
|
|
|
129
|
0
|
|
|
|
|
|
foreach my $sub (@{$sorted_all_subs}) { |
|
0
|
|
|
|
|
|
|
130
|
0
|
|
|
|
|
|
$list_of_subs .= _make_list_of_subs_line( $sub, $column_widths ); |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
0
|
|
|
|
|
|
$list_of_subs .= "\n\n"; |
134
|
0
|
|
|
|
|
|
return $list_of_subs; |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
# MARK: - Private |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
sub _make_list_of_subs_line { |
140
|
0
|
|
|
0
|
|
|
my ( $sub, $column_widths ) = @_; |
141
|
|
|
|
|
|
|
|
142
|
0
|
|
|
|
|
|
my $list_of_subs_line; |
143
|
|
|
|
|
|
|
|
144
|
0
|
|
|
|
|
|
foreach my $col ( 'mccabe_complexity', 'name', 'path', 'lines' ) { |
145
|
|
|
|
|
|
|
$list_of_subs_line |
146
|
0
|
|
|
|
|
|
.= _make_column( $sub->{$col}, $column_widths->{$col} ); |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
0
|
|
|
|
|
|
$list_of_subs_line .= "\n"; |
150
|
0
|
|
|
|
|
|
return $list_of_subs_line; |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
sub _get_column_widths { |
154
|
0
|
|
|
0
|
|
|
my ($main_from_each_file) = @_; |
155
|
|
|
|
|
|
|
|
156
|
0
|
|
|
|
|
|
my $column_widths = { |
157
|
|
|
|
|
|
|
mccabe_complexity => 10, |
158
|
|
|
|
|
|
|
name => 3, |
159
|
|
|
|
|
|
|
path => 4, |
160
|
|
|
|
|
|
|
lines => 4, |
161
|
|
|
|
|
|
|
}; |
162
|
|
|
|
|
|
|
|
163
|
0
|
|
|
|
|
|
foreach my $sub (@{$main_from_each_file}) { |
|
0
|
|
|
|
|
|
|
164
|
0
|
|
|
|
|
|
foreach my $col ( 'mccabe_complexity', 'name', 'path', 'lines' ) { |
165
|
0
|
0
|
|
|
|
|
if ( length( $sub->{$col} ) > $column_widths->{$col} ) { |
166
|
0
|
|
|
|
|
|
$column_widths->{$col} = length( $sub->{$col} ); |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
|
171
|
0
|
|
|
|
|
|
return $column_widths; |
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
sub _make_line { |
175
|
0
|
|
|
0
|
|
|
my ( $key, $value ) = @_; |
176
|
0
|
0
|
|
|
|
|
if ( !defined $value ) { |
177
|
0
|
|
|
|
|
|
$value = 'n/a'; |
178
|
|
|
|
|
|
|
} |
179
|
0
|
|
|
|
|
|
my $line = $key . q{:}; |
180
|
0
|
|
|
|
|
|
$line .= $ONE_SPACE x ( $MAX_PLAINTEXT_LABEL_LENGTH - length $key ); |
181
|
0
|
|
|
|
|
|
$line .= $value . "\n"; |
182
|
0
|
|
|
|
|
|
return $line; |
183
|
|
|
|
|
|
|
} |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
sub _make_headline { |
186
|
0
|
|
|
0
|
|
|
my ($headline) = @_; |
187
|
0
|
|
|
|
|
|
my $formatted_headline = $headline . "\n"; |
188
|
0
|
|
|
|
|
|
$formatted_headline .= q{-} x length $headline; |
189
|
0
|
|
|
|
|
|
$formatted_headline .= "\n"; |
190
|
0
|
|
|
|
|
|
return $formatted_headline; |
191
|
|
|
|
|
|
|
} |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
sub _make_column { |
194
|
0
|
|
|
0
|
|
|
my ( $value, $width ) = @_; |
195
|
|
|
|
|
|
|
|
196
|
0
|
|
|
|
|
|
my $column = $value; |
197
|
0
|
|
|
|
|
|
$column .= $ONE_SPACE x ( $width - length($value) + 2 ); |
198
|
0
|
|
|
|
|
|
return $column; |
199
|
|
|
|
|
|
|
} |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
1; # Keep Perl happy, snuggy, and warm. |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
__END__ |