line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
package File::FilterFuncs; |
3
|
1
|
|
|
1
|
|
61437
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
45
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
32
|
|
5
|
1
|
|
|
1
|
|
5
|
use Exporter (); |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
22
|
|
6
|
1
|
|
|
1
|
|
5
|
use Carp qw(croak confess); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
231
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
BEGIN { |
9
|
1
|
|
|
1
|
|
2
|
our $VERSION = '0.53'; |
10
|
1
|
|
|
|
|
59
|
$VERSION = eval $VERSION; |
11
|
1
|
|
|
|
|
5
|
our @EXPORT_OK = qw(filters filter_funcs $KEEP_LINE $IGNORE_LINE); |
12
|
1
|
|
|
|
|
5
|
our %EXPORT_TAGS = (all => [@EXPORT_OK]); |
13
|
1
|
|
|
|
|
17
|
our @ISA = qw(Exporter); |
14
|
1
|
|
|
|
|
3
|
*KEEP_LINE = \1; |
15
|
1
|
|
|
|
|
993
|
*IGNORE_LINE = \0; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# These are options that accept arguments. |
19
|
|
|
|
|
|
|
my @arg_options = qw(binmode boutmode grepper $/); |
20
|
|
|
|
|
|
|
my %arg_options = map +($_ => 1), @arg_options; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub filters { |
23
|
12
|
|
|
12
|
0
|
13264
|
local $_; |
24
|
12
|
|
|
|
|
53
|
local $/ = $/; |
25
|
12
|
|
|
|
|
26
|
my %opts = &parse_args; |
26
|
|
|
|
|
|
|
|
27
|
12
|
50
|
|
|
|
541
|
open my $in, '<', $opts{source} |
28
|
|
|
|
|
|
|
or croak("Can't open '$opts{source}' for reading: $!"); |
29
|
12
|
50
|
|
|
|
1041
|
open my $out, '>', $opts{dest} |
30
|
|
|
|
|
|
|
or croak("Can't open '$opts{dest}' for writing: $!"); |
31
|
12
|
100
|
|
|
|
38
|
binmode $in, $opts{binmode} if $opts{binmode}; |
32
|
12
|
100
|
|
|
|
30
|
binmode $out, $opts{boutmode} if $opts{boutmode}; |
33
|
12
|
100
|
|
|
|
31
|
$/ = $opts{'$/'} if exists($opts{'$/'}); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
NEXTLINE: |
36
|
12
|
|
|
|
|
212
|
while ($_ = <$in>) { |
37
|
|
|
|
|
|
|
|
38
|
240
|
|
|
|
|
286
|
foreach my $transform (@{$opts{subs}}) { |
|
240
|
|
|
|
|
465
|
|
39
|
171
|
100
|
|
|
|
392
|
next NEXTLINE unless $transform->(); |
40
|
|
|
|
|
|
|
} |
41
|
230
|
|
|
|
|
1258
|
print $out $_; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
12
|
50
|
|
|
|
630
|
close $out or croak("Can't close '$opts{dest}'"); |
45
|
12
|
50
|
|
|
|
221
|
close $in or croak("Can't close '$opts{source}'"); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub parse_args { |
50
|
12
|
|
|
12
|
0
|
49
|
local $_; |
51
|
12
|
|
|
|
|
18
|
my %hash; |
52
|
|
|
|
|
|
|
|
53
|
12
|
50
|
33
|
|
|
76
|
die "No source file name" unless ($_[0] && '' eq ref $_[0]); |
54
|
12
|
50
|
33
|
|
|
59
|
die "No destination file name" unless ($_[-1] && '' eq ref $_[-1]); |
55
|
12
|
|
|
|
|
32
|
$hash{source} = '' . shift; |
56
|
12
|
|
|
|
|
23
|
$hash{dest} = '' . pop; |
57
|
|
|
|
|
|
|
|
58
|
12
|
50
|
|
|
|
36
|
if ($hash{dest} eq $hash{source}) { |
59
|
0
|
|
|
|
|
0
|
die("Cannot filter '$hash{source}' onto itself."); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
12
|
|
|
|
|
28
|
while (@_) { |
63
|
13
|
|
|
|
|
21
|
$_ = shift; |
64
|
13
|
100
|
|
|
|
53
|
if ($arg_options{$_}) { |
|
|
50
|
|
|
|
|
|
65
|
4
|
|
|
|
|
15
|
$hash{$_} = shift; |
66
|
|
|
|
|
|
|
} elsif ('CODE' eq ref($_)) { |
67
|
9
|
|
|
|
|
10
|
push @{$hash{subs}}, $_; |
|
9
|
|
|
|
|
42
|
|
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
12
|
|
|
|
|
69
|
%hash; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
BEGIN { |
75
|
1
|
|
|
1
|
|
32
|
*filter_funcs = \&filters; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
1; |
81
|
|
|
|
|
|
|
|