line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::Edge; |
2
|
3
|
|
|
3
|
|
202587
|
use strict; |
|
3
|
|
|
|
|
10
|
|
|
3
|
|
|
|
|
135
|
|
3
|
3
|
|
|
3
|
|
17
|
use warnings; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
157
|
|
4
|
3
|
|
|
3
|
|
4624
|
use Getopt::Long qw/GetOptionsFromArray/; |
|
3
|
|
|
|
|
50470
|
|
|
3
|
|
|
|
|
22
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub run { |
9
|
15
|
|
|
15
|
1
|
33568
|
my $self = shift; |
10
|
15
|
|
|
|
|
49
|
my @argv = @_; |
11
|
|
|
|
|
|
|
|
12
|
15
|
|
|
|
|
34
|
my $config = +{}; |
13
|
15
|
|
|
|
|
58
|
_merge_opt($config, @argv); |
14
|
|
|
|
|
|
|
|
15
|
15
|
|
|
|
|
52
|
_main($config); |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub _main { |
19
|
15
|
|
|
15
|
|
28
|
my $config = shift; |
20
|
|
|
|
|
|
|
|
21
|
15
|
|
|
|
|
25
|
for my $file (@{$config->{file}}) { |
|
15
|
|
|
|
|
60
|
|
22
|
18
|
50
|
|
|
|
363
|
unless(-e $file) { |
23
|
0
|
|
|
|
|
0
|
print "cannot open '$file' for reading: No such file or directory\n"; |
24
|
0
|
|
|
|
|
0
|
next; |
25
|
|
|
|
|
|
|
} |
26
|
18
|
100
|
|
|
|
25
|
if ( scalar @{$config->{file}} > 1 ) { |
|
18
|
|
|
|
|
65
|
|
27
|
6
|
|
|
|
|
165
|
print "==> $file <==\n"; |
28
|
|
|
|
|
|
|
} |
29
|
18
|
|
|
|
|
54
|
_show_file($file, $config); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub _show_file { |
34
|
18
|
|
|
18
|
|
40
|
my ($file, $config) = @_; |
35
|
|
|
|
|
|
|
|
36
|
18
|
|
|
|
|
27
|
my $c = 0; |
37
|
18
|
|
|
|
|
30
|
my $total = 0; |
38
|
18
|
|
|
|
|
26
|
my $last_line = ''; |
39
|
18
|
|
|
|
|
45
|
my @grep = @{$config->{grep}}; |
|
18
|
|
|
|
|
53
|
|
40
|
18
|
|
|
|
|
29
|
my @grepv = @{$config->{grepv}}; |
|
18
|
|
|
|
|
41
|
|
41
|
|
|
|
|
|
|
|
42
|
18
|
50
|
|
|
|
653
|
open my $fh, '<', $file or die "cannot open '$file' for reading"; |
43
|
|
|
|
|
|
|
|
44
|
18
|
|
|
|
|
358
|
while ( my $line = <$fh> ) { |
45
|
39
|
|
|
|
|
58
|
chomp $line; |
46
|
39
|
|
|
|
|
50
|
$total++; |
47
|
39
|
100
|
100
|
|
|
126
|
next if @grepv && _match_grepv($line, @grepv); |
48
|
32
|
100
|
100
|
|
|
141
|
next if @grep && !_match_grep($line, @grep); |
49
|
25
|
|
|
|
|
32
|
$c++; |
50
|
25
|
100
|
|
|
|
60
|
if ($c == 1) { |
51
|
16
|
|
|
|
|
833
|
print "$c: $line\n"; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
else { |
54
|
9
|
|
|
|
|
65
|
$last_line = $line; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
18
|
|
|
|
|
213
|
close $fh; |
59
|
|
|
|
|
|
|
|
60
|
18
|
100
|
|
|
|
147
|
print "$c: $last_line\n" if $last_line; |
61
|
|
|
|
|
|
|
|
62
|
18
|
100
|
|
|
|
202
|
if ($config->{total}) { |
63
|
1
|
50
|
|
|
|
4
|
my $plural = $total > 1 ? 's' : ''; |
64
|
1
|
|
|
|
|
22
|
print "total: $total line". $plural. "\n"; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub _match_grep { |
69
|
14
|
|
|
14
|
|
114
|
my ($line, @grep) = @_; |
70
|
|
|
|
|
|
|
|
71
|
14
|
|
|
|
|
21
|
my $cond_count = scalar @grep; |
72
|
14
|
|
|
|
|
20
|
my $match_count = 0; |
73
|
|
|
|
|
|
|
|
74
|
14
|
|
|
|
|
20
|
for my $g (@grep) { |
75
|
17
|
100
|
|
|
|
150
|
if ($line =~ m!\Q$g\E!) { |
76
|
8
|
|
|
|
|
25
|
$match_count++; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
14
|
100
|
|
|
|
112
|
return 1 if $cond_count == $match_count; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub _match_grepv { |
84
|
15
|
|
|
15
|
|
33
|
my ($line, @grepv) = @_; |
85
|
|
|
|
|
|
|
|
86
|
15
|
|
|
|
|
45
|
for my $g (@grepv) { |
87
|
17
|
100
|
|
|
|
137
|
if ($line =~ m!\Q$g\E!) { |
88
|
7
|
|
|
|
|
59
|
return 1; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub _merge_opt { |
94
|
15
|
|
|
15
|
|
35
|
my ($config, @argv) = @_; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
GetOptionsFromArray( |
97
|
|
|
|
|
|
|
\@argv, |
98
|
|
|
|
|
|
|
't|total-count' => \$config->{total}, |
99
|
|
|
|
|
|
|
'g|grep=s@' => \$config->{grep}, |
100
|
|
|
|
|
|
|
'gv|grepv=s@' => \$config->{grepv}, |
101
|
|
|
|
|
|
|
# 'n|line=i' => \$config->{n}, |
102
|
|
|
|
|
|
|
'f|file=s@' => \$config->{file}, |
103
|
|
|
|
|
|
|
'h|help' => sub { |
104
|
0
|
|
|
0
|
|
0
|
_show_usage(1); |
105
|
|
|
|
|
|
|
}, |
106
|
|
|
|
|
|
|
'v|version' => sub { |
107
|
0
|
|
|
0
|
|
0
|
print "$0 $VERSION\n"; |
108
|
0
|
|
|
|
|
0
|
exit 1; |
109
|
|
|
|
|
|
|
}, |
110
|
15
|
50
|
|
|
|
217
|
) or _show_usage(2); |
111
|
|
|
|
|
|
|
|
112
|
15
|
100
|
|
|
|
14430
|
defined $config->{grep} or $config->{grep} = []; |
113
|
15
|
100
|
|
|
|
58
|
defined $config->{grepv} or $config->{grepv} = []; |
114
|
|
|
|
|
|
|
|
115
|
15
|
|
|
|
|
42
|
push(@{$config->{file}}, $_) for @argv; |
|
18
|
|
|
|
|
79
|
|
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub _show_usage { |
119
|
0
|
|
|
0
|
|
|
my $exitval = shift; |
120
|
|
|
|
|
|
|
|
121
|
0
|
|
|
|
|
|
require Pod::Usage; |
122
|
0
|
|
|
|
|
|
Pod::Usage::pod2usage($exitval); |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
1; |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
__END__ |