line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::p5find; |
2
|
3
|
|
|
3
|
|
610209
|
use v5.18; |
|
3
|
|
|
|
|
20
|
|
3
|
|
|
|
|
|
|
our $VERSION = "0.03"; |
4
|
|
|
|
|
|
|
|
5
|
3
|
|
|
3
|
|
1366
|
use File::Next; |
|
3
|
|
|
|
|
5532
|
|
|
3
|
|
|
|
|
87
|
|
6
|
3
|
|
|
3
|
|
1260
|
use PPI::Document::File; |
|
3
|
|
|
|
|
311464
|
|
|
3
|
|
|
|
|
119
|
|
7
|
3
|
|
|
3
|
|
1683
|
use PPIx::QuoteLike; |
|
3
|
|
|
|
|
49019
|
|
|
3
|
|
|
|
|
104
|
|
8
|
|
|
|
|
|
|
|
9
|
3
|
|
|
3
|
|
25
|
use Exporter 'import'; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
1331
|
|
10
|
|
|
|
|
|
|
our @EXPORT_OK = qw( p5_doc_iterator |
11
|
|
|
|
|
|
|
p5_source_file_iterator |
12
|
|
|
|
|
|
|
print_file_linenum_line ); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
my %EXCLUDED = ( |
15
|
|
|
|
|
|
|
'.git' => 1, |
16
|
|
|
|
|
|
|
'.svn' => 1, |
17
|
|
|
|
|
|
|
'CVS' => 1, |
18
|
|
|
|
|
|
|
'node_modules' => 1, # You won't hide your Perl5 code there, right ? |
19
|
|
|
|
|
|
|
); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub p5_doc_iterator { |
22
|
3
|
|
|
3
|
0
|
11236
|
my (@paths) = @_; |
23
|
3
|
|
|
|
|
11
|
my $files = p5_source_file_iterator(@paths); |
24
|
|
|
|
|
|
|
return sub { |
25
|
9
|
|
|
9
|
|
9827
|
my $f = $files->(); |
26
|
9
|
100
|
|
|
|
26
|
return undef unless defined($f); |
27
|
8
|
|
|
|
|
62
|
my $dom = PPI::Document::File->new( $f, readonly => 1 ); |
28
|
8
|
|
|
|
|
280885
|
$dom->index_locations; |
29
|
8
|
|
|
|
|
60440
|
return $dom; |
30
|
3
|
|
|
|
|
15
|
}; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub p5_source_file_iterator { |
34
|
5
|
|
|
5
|
0
|
6835
|
my (@paths) = @_; |
35
|
|
|
|
|
|
|
my $files = File::Next::files( |
36
|
16
|
|
|
16
|
|
1829
|
+{ descend_filter => sub { ! $EXCLUDED{$_} } }, |
37
|
|
|
|
|
|
|
@paths |
38
|
5
|
|
|
|
|
40
|
); |
39
|
|
|
|
|
|
|
return sub { |
40
|
12
|
|
|
12
|
|
27
|
my $f; |
41
|
12
|
|
100
|
|
|
21
|
do { $f = $files->() } while defined($f) && ! is_perl5_source_file($f); |
|
20
|
|
|
|
|
52
|
|
42
|
12
|
|
|
|
|
59
|
return $f; |
43
|
|
|
|
|
|
|
} |
44
|
5
|
|
|
|
|
626
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub is_perl5_source_file { |
47
|
19
|
|
|
19
|
0
|
1888
|
my ($file) = @_; |
48
|
19
|
100
|
|
|
|
149
|
return 1 if $file =~ / \.(?: t|p[ml]|pod|comp ) $/xi; |
49
|
8
|
50
|
|
|
|
32
|
return 0 if $file =~ / \. /xi; |
50
|
0
|
0
|
|
|
|
|
if (open my $fh, '<', $file) { |
51
|
0
|
|
|
|
|
|
my $line = <$fh>; |
52
|
0
|
0
|
|
|
|
|
return 1 if $line =~ m{^#!.*perl}; |
53
|
|
|
|
|
|
|
} |
54
|
0
|
|
|
|
|
|
return 0; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub print_file_linenum_line { |
58
|
0
|
|
|
0
|
0
|
|
my ($file, $to_print) = @_; |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
my $line_number = 0; |
61
|
0
|
|
|
|
|
|
open my $fh, "<", $file; |
62
|
0
|
|
|
|
|
|
while (my $line = <$fh>) { |
63
|
0
|
|
|
|
|
|
$line_number++; |
64
|
0
|
0
|
|
|
|
|
if ( $to_print->{$line_number} ) { |
65
|
0
|
|
|
|
|
|
print "${file}:${line_number}:${line}"; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
} |
68
|
0
|
|
|
|
|
|
close($fh); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
1; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
__END__ |