« lib/Perl/Critic/Policy/NamingConventions/ProhibitAmbiguousNames.pm
↑ Summary
lib/Perl/Critic/Policy/Modules/ProhibitAutomaticExportation.pm »
| 1 | package Perl::Critic::Statistics; | ||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||
| 3 | 40 | ▶ | use 5.010001; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 4 | 40 | ▶ | use strict; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 5 | 40 | ▶ | use warnings; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||
| 7 | 40 | ▶ | use English qw(-no_match_vars); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||
| 9 | 40 | ▶ | use Perl::Critic::Utils::McCabe qw{ calculate_mccabe_of_sub }; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||
| 11 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||
| 13 | 40 | our $VERSION = '1.156'; | |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||
| 15 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||
| 17 | 89 | ▶ | sub new { | ||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||
| 18 | 89 | my ( $class ) = @_; | |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||
| 20 | 89 | my $self = bless {}, $class; | |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||
| 22 | 89 | $self->{_modules} = 0; | |||||||||||||||||||||||||||||
| 23 | 89 | $self->{_subs} = 0; | |||||||||||||||||||||||||||||
| 24 | 89 | $self->{_statements} = 0; | |||||||||||||||||||||||||||||
| 25 | 89 | $self->{_lines} = 0; | |||||||||||||||||||||||||||||
| 26 | 89 | $self->{_lines_of_blank} = 0; | |||||||||||||||||||||||||||||
| 27 | 89 | $self->{_lines_of_comment} = 0; | |||||||||||||||||||||||||||||
| 28 | 89 | $self->{_lines_of_data} = 0; | |||||||||||||||||||||||||||||
| 29 | 89 | $self->{_lines_of_perl} = 0; | |||||||||||||||||||||||||||||
| 30 | 89 | $self->{_lines_of_pod} = 0; | |||||||||||||||||||||||||||||
| 31 | 89 | $self->{_violations_by_policy} = {}; | |||||||||||||||||||||||||||||
| 32 | 89 | $self->{_violations_by_severity} = {}; | |||||||||||||||||||||||||||||
| 33 | 89 | $self->{_total_violations} = 0; | |||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||
| 35 | 89 | return $self; | |||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||
| 38 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||
| 40 | 85 | ▶ | sub accumulate { | ||||||||||||||||||||||||||||
|
Subroutine
accumulate: called CC=13 SCAR=25.6
Pod
documented
| |||||||||||||||||||||||||||||||
| 41 | 85 | my ($self, $doc, $violations) = @_; | |||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||
| 43 | 85 | $self->{_modules}++; | |||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||
| 45 | 85 | my $subs = $doc->find('PPI::Statement::Sub'); | |||||||||||||||||||||||||||||
| 46 | 85 | ▶ | if ($subs) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 47 | 9 | foreach my $sub ( @{$subs} ) { | |||||||||||||||||||||||||||||
| 48 | 10 | $self->{_subs}++; | |||||||||||||||||||||||||||||
| 49 | 10 | $self->{_subs_total_mccabe} += calculate_mccabe_of_sub( $sub ); | |||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||
| 53 | 85 | my $statements = $doc->find('PPI::Statement'); | |||||||||||||||||||||||||||||
| 54 | 85 | ▶ | $self->{_statements} += $statements ? scalar @{$statements} : 0; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||
| 56 | ## no critic (RequireDotMatchAnything, RequireExtendedFormatting, RequireLineBoundaryMatching) | ||||||||||||||||||||||||||||||
| 57 | 85 | my @lines = split /$INPUT_RECORD_SEPARATOR/, $doc->serialize(); | |||||||||||||||||||||||||||||
| 58 | ## use critic | ||||||||||||||||||||||||||||||
| 59 | 85 | $self->{_lines} += scalar @lines; | |||||||||||||||||||||||||||||
| 60 | { | ||||||||||||||||||||||||||||||
| 61 | 85 | my ( $in_data, $in_pod ); | |||||||||||||||||||||||||||||
| 62 | 85 | foreach ( @lines ) { | |||||||||||||||||||||||||||||
| 63 | 1185 | ▶ | if ( q{=} eq substr $_, 0, 1 ) { ## no critic (ProhibitCascadingIfElse) | ||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||
| 64 | 64 | $in_pod = not m/ \A \s* =cut \b /smx; | |||||||||||||||||||||||||||||
| 65 | 64 | $self->{_lines_of_pod}++; | |||||||||||||||||||||||||||||
| 66 | } elsif ( $in_pod ) { | ||||||||||||||||||||||||||||||
| 67 | 99 | $self->{_lines_of_pod}++; | |||||||||||||||||||||||||||||
| 68 | ▶ | } elsif ( q{__END__} eq $_ || q{__DATA__} eq $_ ) { | |||||||||||||||||||||||||||||
|
Condition100%3/3
"__END__" eq $_ or "__DATA__" eq $_
MC/DC100%2/2
"__END__" eq $_ or "__DATA__" eq $_
"__END__" eq $_
"__DATA__" eq $_
Truth table100%3/3
A or B
A= "__END__" eq $_B= "__DATA__" eq $_
| |||||||||||||||||||||||||||||||
| 69 | 59 | $in_data = 1; | |||||||||||||||||||||||||||||
| 70 | 59 | $self->{_lines_of_perl}++; | |||||||||||||||||||||||||||||
| 71 | } elsif ( $in_data ) { | ||||||||||||||||||||||||||||||
| 72 | 89 | $self->{_lines_of_data}++; | |||||||||||||||||||||||||||||
| 73 | } elsif ( m/ \A \s* \# /smx ) { | ||||||||||||||||||||||||||||||
| 74 | 91 | $self->{_lines_of_comment}++; | |||||||||||||||||||||||||||||
| 75 | } elsif ( m/ \A \s* \z /smx ) { | ||||||||||||||||||||||||||||||
| 76 | 228 | $self->{_lines_of_blank}++; | |||||||||||||||||||||||||||||
| 77 | } else { | ||||||||||||||||||||||||||||||
| 78 | 555 | $self->{_lines_of_perl}++; | |||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||
| 83 | 85 | foreach my $violation ( @{ $violations } ) { | |||||||||||||||||||||||||||||
| 84 | 159 | $self->{_violations_by_severity}->{ $violation->severity() }++; | |||||||||||||||||||||||||||||
| 85 | 159 | $self->{_violations_by_policy}->{ $violation->policy() }++; | |||||||||||||||||||||||||||||
| 86 | 159 | $self->{_total_violations}++; | |||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||
| 89 | 85 | return; | |||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||
| 92 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||
| 94 | 3 | ▶ | sub modules { | ||||||||||||||||||||||||||||
|
Subroutine
modules: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||
| 95 | 3 | my ( $self ) = @_; | |||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||
| 97 | 3 | return $self->{_modules}; | |||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||
| 100 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||
| 102 | 5 | ▶ | sub subs { | ||||||||||||||||||||||||||||
|
Subroutine
subs: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||
| 103 | 5 | my ( $self ) = @_; | |||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||
| 105 | 5 | return $self->{_subs}; | |||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||
| 108 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||
| 110 | 3 | ▶ | sub statements { | ||||||||||||||||||||||||||||
|
Subroutine
statements: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||
| 111 | 3 | my ( $self ) = @_; | |||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||
| 113 | 3 | return $self->{_statements}; | |||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||
| 116 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||
| 118 | 3 | ▶ | sub lines { | ||||||||||||||||||||||||||||
|
Subroutine
lines: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||
| 119 | 3 | my ( $self ) = @_; | |||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||
| 121 | 3 | return $self->{_lines}; | |||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||
| 124 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||
| 126 | 0 | ▶ | sub lines_of_blank { | ||||||||||||||||||||||||||||
|
Subroutine
lines_of_blank: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||
| 127 | 0 | my ( $self ) = @_; | |||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||
| 129 | 0 | return $self->{_lines_of_blank}; | |||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||
| 132 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||
| 134 | 0 | ▶ | sub lines_of_comment { | ||||||||||||||||||||||||||||
|
Subroutine
lines_of_comment: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||
| 135 | 0 | my ( $self ) = @_; | |||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||
| 137 | 0 | return $self->{_lines_of_comment}; | |||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||
| 140 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||
| 142 | 0 | ▶ | sub lines_of_data { | ||||||||||||||||||||||||||||
|
Subroutine
lines_of_data: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||
| 143 | 0 | my ( $self ) = @_; | |||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||
| 145 | 0 | return $self->{_lines_of_data}; | |||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||
| 148 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||
| 150 | 0 | ▶ | sub lines_of_perl { | ||||||||||||||||||||||||||||
|
Subroutine
lines_of_perl: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||
| 151 | 0 | my ( $self ) = @_; | |||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||
| 153 | 0 | return $self->{_lines_of_perl}; | |||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||
| 156 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||
| 158 | 0 | ▶ | sub lines_of_pod { | ||||||||||||||||||||||||||||
|
Subroutine
lines_of_pod: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||
| 159 | 0 | my ( $self ) = @_; | |||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||
| 161 | 0 | return $self->{_lines_of_pod}; | |||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||
| 164 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||
| 166 | 1 | ▶ | sub _subs_total_mccabe { | ||||||||||||||||||||||||||||
|
Subroutine
_subs_total_mccabe: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 167 | 1 | my ( $self ) = @_; | |||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||
| 169 | 1 | return $self->{_subs_total_mccabe}; | |||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||
| 172 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||
| 174 | 0 | ▶ | sub violations_by_severity { | ||||||||||||||||||||||||||||
|
Subroutine
violations_by_severity: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||
| 175 | 0 | my ( $self ) = @_; | |||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||
| 177 | 0 | return $self->{_violations_by_severity}; | |||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||
| 180 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||
| 182 | 0 | ▶ | sub violations_by_policy { | ||||||||||||||||||||||||||||
|
Subroutine
violations_by_policy: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||
| 183 | 0 | my ( $self ) = @_; | |||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||
| 185 | 0 | return $self->{_violations_by_policy}; | |||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||
| 188 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||
| 190 | 4 | ▶ | sub total_violations { | ||||||||||||||||||||||||||||
|
Subroutine
total_violations: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||
| 191 | 4 | my ( $self ) = @_; | |||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||
| 193 | 4 | return $self->{_total_violations}; | |||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||
| 196 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||
| 198 | 2 | ▶ | sub statements_other_than_subs { | ||||||||||||||||||||||||||||
|
Subroutine
statements_other_than_subs: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||
| 199 | 2 | my ( $self ) = @_; | |||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||
| 201 | 2 | return $self->statements() - $self->subs(); | |||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||
| 204 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||
| 206 | 1 | ▶ | sub average_sub_mccabe { | ||||||||||||||||||||||||||||
|
Subroutine
average_sub_mccabe: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||
| 207 | 1 | my ( $self ) = @_; | |||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||
| 209 | 1 | ▶ | return if $self->subs() == 0; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||
| 211 | 1 | return $self->_subs_total_mccabe() / $self->subs(); | |||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||
| 214 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||
| 216 | 1 | ▶ | sub violations_per_file { | ||||||||||||||||||||||||||||
|
Subroutine
violations_per_file: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||
| 217 | 1 | my ( $self ) = @_; | |||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||
| 219 | 1 | ▶ | return if $self->modules() == 0; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||
| 221 | 1 | return $self->total_violations() / $self->modules(); | |||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||
| 224 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||
| 226 | 1 | ▶ | sub violations_per_statement { | ||||||||||||||||||||||||||||
|
Subroutine
violations_per_statement: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||
| 227 | 1 | my ( $self ) = @_; | |||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||
| 229 | 1 | my $statements = $self->statements_other_than_subs(); | |||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||
| 231 | 1 | ▶ | return if $statements == 0; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||
| 233 | 1 | return $self->total_violations() / $statements; | |||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||
| 236 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||
| 238 | 1 | ▶ | sub violations_per_line_of_code { | ||||||||||||||||||||||||||||
|
Subroutine
violations_per_line_of_code: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||
| 239 | 1 | my ( $self ) = @_; | |||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||
| 241 | 1 | ▶ | return if $self->lines() == 0; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||
| 243 | 1 | return $self->total_violations() / $self->lines(); | |||||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||
| 246 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||
| 248 | 40 | 1; | |||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||
| 250 | __END__ | ||||||||||||||||||||||||||||||