| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package App::prefixcat; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
383985
|
use strict; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
64
|
|
|
4
|
1
|
|
|
1
|
|
8
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
395
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY |
|
7
|
|
|
|
|
|
|
our $DATE = '2024-08-11'; # DATE |
|
8
|
|
|
|
|
|
|
our $DIST = 'App-prefixcat'; # DIST |
|
9
|
|
|
|
|
|
|
our $VERSION = '0.002'; # VERSION |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub run { |
|
12
|
0
|
|
|
0
|
0
|
|
my %opts = @_; |
|
13
|
|
|
|
|
|
|
|
|
14
|
0
|
|
|
|
|
|
my @ifh; # input handles |
|
15
|
|
|
|
|
|
|
my @ifnames;; |
|
16
|
0
|
0
|
|
|
|
|
if (@ARGV) { |
|
17
|
0
|
|
|
|
|
|
for (@ARGV) { |
|
18
|
0
|
|
|
|
|
|
my $ifh; |
|
19
|
0
|
0
|
|
|
|
|
if ($_ eq '-') { |
|
20
|
0
|
|
|
|
|
|
$ifh = *STDIN; |
|
21
|
|
|
|
|
|
|
} else { |
|
22
|
0
|
0
|
|
|
|
|
die "Is a directory: $_\n" if -d $_; |
|
23
|
0
|
0
|
|
|
|
|
open $ifh, "<", $_ or die "Can't open input file $_: $!\n"; |
|
24
|
|
|
|
|
|
|
} |
|
25
|
0
|
|
|
|
|
|
push @ifh, $ifh; |
|
26
|
0
|
|
|
|
|
|
push @ifnames, $_; |
|
27
|
|
|
|
|
|
|
} |
|
28
|
|
|
|
|
|
|
} else { |
|
29
|
0
|
|
|
|
|
|
push @ifh, *STDIN; |
|
30
|
0
|
|
|
|
|
|
push @ifnames, "-"; |
|
31
|
|
|
|
|
|
|
} |
|
32
|
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
|
for my $filenum (1 .. @ifh) { |
|
34
|
0
|
|
|
|
|
|
my $ifh = $ifh[$filenum-1]; |
|
35
|
0
|
|
|
|
|
|
my $ifname = $ifnames[$filenum-1]; |
|
36
|
0
|
|
|
|
|
|
local $main::filename = $ifname; |
|
37
|
0
|
|
|
|
|
|
local $main::filenum = $filenum; |
|
38
|
0
|
|
|
|
|
|
my $linenum = 0; |
|
39
|
0
|
|
|
|
|
|
while (defined(my $line = <$ifh>)) { |
|
40
|
0
|
|
|
|
|
|
$linenum++; |
|
41
|
0
|
|
|
|
|
|
local $main::linenum = $linenum; |
|
42
|
0
|
0
|
|
|
|
|
if ($opts{eval}) { |
|
43
|
|
|
|
|
|
|
{ |
|
44
|
0
|
|
|
|
|
|
local $_ = $line; |
|
|
0
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
my $res = $opts{eval}->($_); |
|
46
|
0
|
|
0
|
|
|
|
print $res // $_; |
|
47
|
|
|
|
|
|
|
} |
|
48
|
|
|
|
|
|
|
} else { |
|
49
|
0
|
|
|
|
|
|
print sprintf($opts{format}, $ifname) . $opts{separator} . $line; |
|
50
|
|
|
|
|
|
|
} |
|
51
|
|
|
|
|
|
|
} |
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
} |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
1; |
|
57
|
|
|
|
|
|
|
# ABSTRACT: Like Unix `cat` but by default prefix each line with filename |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
__END__ |