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