line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perl::Metrics::Lite::Analysis::Util; |
2
|
6
|
|
|
6
|
|
198271
|
use strict; |
|
6
|
|
|
|
|
59
|
|
|
6
|
|
|
|
|
173
|
|
3
|
6
|
|
|
6
|
|
31
|
use warnings; |
|
6
|
|
|
|
|
14
|
|
|
6
|
|
|
|
|
220
|
|
4
|
6
|
|
|
6
|
|
524
|
use English qw(-no_match_vars); |
|
6
|
|
|
|
|
3593
|
|
|
6
|
|
|
|
|
38
|
|
5
|
6
|
|
|
6
|
|
2823
|
use Readonly; |
|
6
|
|
|
|
|
3864
|
|
|
6
|
|
|
|
|
3540
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
Readonly::Scalar my $ALL_NEWLINES_REGEX => ## no critic |
8
|
|
|
|
|
|
|
qr/ ( \Q$INPUT_RECORD_SEPARATOR\E ) /sxm; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
Readonly::Scalar my $LAST_CHARACTER => -1; ## no critic |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub get_node_length { |
13
|
76
|
|
|
76
|
1
|
8499
|
my $node = shift; |
14
|
76
|
|
|
|
|
139
|
my $eval_result = eval { $node = prune_non_code_lines($node); }; |
|
76
|
|
|
|
|
163
|
|
15
|
76
|
50
|
|
|
|
307
|
return 0 if not $eval_result; |
16
|
76
|
50
|
|
|
|
198
|
return 0 if ( !defined $node ); |
17
|
76
|
|
|
|
|
240
|
my $string = $node->content; |
18
|
76
|
50
|
|
|
|
20319
|
return 0 if ( !length $string ); |
19
|
|
|
|
|
|
|
|
20
|
76
|
|
|
|
|
202
|
$string = _normailze_string($string); |
21
|
76
|
|
|
|
|
225
|
my $line_count = _count_lines($string); |
22
|
|
|
|
|
|
|
|
23
|
76
|
|
|
|
|
287
|
return $line_count; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub _normailze_string { |
27
|
76
|
|
|
76
|
|
139
|
my $string = shift; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# Replace whitespace-newline with newline |
30
|
76
|
|
|
|
|
1075
|
$string |
31
|
|
|
|
|
|
|
=~ s/ \s+ \Q$INPUT_RECORD_SEPARATOR\E /$INPUT_RECORD_SEPARATOR/smxg; |
32
|
76
|
|
|
|
|
629
|
$string =~ s/\Q$INPUT_RECORD_SEPARATOR\E /$INPUT_RECORD_SEPARATOR/smxg; |
33
|
76
|
|
|
|
|
275
|
$string =~ s/ \A \s+ //msx; # Remove leading whitespace |
34
|
76
|
|
|
|
|
250
|
$string; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub _count_lines { |
38
|
76
|
|
|
76
|
|
137
|
my $string = shift; |
39
|
76
|
|
|
|
|
670
|
my @newlines = ( $string =~ /$ALL_NEWLINES_REGEX/smxg ); |
40
|
76
|
|
|
|
|
162
|
my $line_count = scalar @newlines; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# if the string is not empty and the last character is not a newline then add 1 |
43
|
76
|
100
|
|
|
|
202
|
if ( length $string ) { |
44
|
72
|
|
|
|
|
192
|
my $last_char = substr $string, $LAST_CHARACTER, 1; |
45
|
72
|
100
|
|
|
|
202
|
if ( $last_char ne "$INPUT_RECORD_SEPARATOR" ) { |
46
|
61
|
|
|
|
|
115
|
$line_count++; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
} |
49
|
76
|
|
|
|
|
174
|
return $line_count; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub get_packages { |
53
|
18
|
|
|
18
|
1
|
44
|
my $document = shift; |
54
|
|
|
|
|
|
|
|
55
|
18
|
|
|
|
|
44
|
my @unique_packages = (); |
56
|
18
|
|
|
|
|
75
|
my $found_packages = $document->find('PPI::Statement::Package'); |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
return \@unique_packages |
59
|
18
|
100
|
|
|
|
51100
|
if ( |
60
|
|
|
|
|
|
|
!Perl::Metrics::Lite::Analysis::Util::is_ref( $found_packages, 'ARRAY' ) ); |
61
|
|
|
|
|
|
|
|
62
|
9
|
|
|
|
|
25
|
my %seen_packages = (); |
63
|
|
|
|
|
|
|
|
64
|
9
|
|
|
|
|
20
|
foreach my $package ( @{$found_packages} ) { |
|
9
|
|
|
|
|
26
|
|
65
|
15
|
|
|
|
|
216
|
$seen_packages{ $package->namespace() }++; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
9
|
|
|
|
|
300
|
@unique_packages = sort keys %seen_packages; |
69
|
|
|
|
|
|
|
|
70
|
9
|
|
|
|
|
44
|
return \@unique_packages; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub prune_non_code_lines { |
74
|
76
|
|
|
76
|
0
|
130
|
my $document = shift; |
75
|
76
|
50
|
|
|
|
183
|
if ( !defined $document ) { |
76
|
0
|
|
|
|
|
0
|
Carp::confess('Did not supply a document!'); |
77
|
|
|
|
|
|
|
} |
78
|
76
|
|
|
|
|
331
|
$document->prune('PPI::Token::Comment'); |
79
|
76
|
|
|
|
|
151535
|
$document->prune('PPI::Token::Pod'); |
80
|
76
|
|
|
|
|
140745
|
$document->prune('PPI::Token::End'); |
81
|
|
|
|
|
|
|
|
82
|
76
|
|
|
|
|
139631
|
return $document; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub is_ref { |
86
|
65
|
|
|
65
|
1
|
3286
|
my $thing = shift; |
87
|
65
|
|
|
|
|
126
|
my $type = shift; |
88
|
65
|
|
|
|
|
132
|
my $ref = ref $thing; |
89
|
65
|
100
|
|
|
|
264
|
return if !$ref; |
90
|
35
|
100
|
|
|
|
108
|
return if ( $ref ne $type ); |
91
|
34
|
|
|
|
|
134
|
return $ref; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
1; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
__END__ |