blib/lib/File/FilterFuncs.pm

filter: Statementstmt 43.4% 23 / 53 Branchbran 0.0% 0 / 30 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 75.0% 6 / 8 Podpod 0.0% 0 / 2 totaltotal 28.1% 29 / 103 CC 19 SCAR 44.7
CC
19
Cov
26%
filters
132.0
parse_args
90.0
BEGIN
1.0
CRAP 87.2
↑ Summary
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
BranchTrueFalseTotal
open my $in, "<", $opts{"source"} or croak(qq[Can't open '$opts{"source"}' for reading: $!]) 0 0 0
29 open my $out, '>', $opts{dest}
30 0 ▶ or croak("Can't open '$opts{dest}' for writing: $!");
Branch: 1 branch
BranchTrueFalseTotal
open my $out, ">", $opts{"dest"} or croak(qq[Can't open '$opts{"dest"}' for writing: $!]) 0 0 0
31 0 ▶ binmode $in, $opts{binmode} if $opts{binmode};
Branch: 1 branch
BranchTrueFalseTotal
if $opts{"binmode"} 0 0 0
32 0 ▶ binmode $out, $opts{boutmode} if $opts{boutmode};
Branch: 1 branch
BranchTrueFalseTotal
if $opts{"boutmode"} 0 0 0
33 0 ▶ $/ = $opts{'$/'} if exists($opts{'$/'});
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts{"\$/"} 0 0 0
34  
35 NEXTLINE:
36 0 ▶ while ($_ = <$in>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $in)) 0 0 0
37  
38 0 foreach my $transform (@{$opts{subs}}) {
39 0 ▶ next NEXTLINE unless $transform->();
Branch: 1 branch
BranchTrueFalseTotal
unless &$transform() 0 0 0
40 }
41 0 print $out $_;
42 }
43  
44 0 ▶ close $out or croak("Can't close '$opts{dest}'");
Branch: 1 branch
BranchTrueFalseTotal
close $out or croak(qq[Can't close '$opts{"dest"}']) 0 0 0
45 0 ▶ close $in or croak("Can't close '$opts{source}'");
Branch: 1 branch
BranchTrueFalseTotal
close $in or croak(qq[Can't close '$opts{"source"}']) 0 0 0
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
BranchTrueFalseTotal
unless $_[0] and "" eq ref $_[0] 0 0 0
Condition0%0/3
$_[0] and "" eq ref $_[0]
!ll&&!rl&&r
000
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]
ABresult
0X0
100
111
54 0 ▶ die "No destination file name" unless ($_[-1] && '' eq ref $_[-1]);
Branch: 1 branch
BranchTrueFalseTotal
unless $_[-1] and "" eq ref $_[-1] 0 0 0
Condition0%0/3
$_[-1] and "" eq ref $_[-1]
!ll&&!rl&&r
000
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]
ABresult
0X0
100
111
55 0 $hash{source} = '' . shift;
56 0 $hash{dest} = '' . pop;
57  
58 0 ▶ if ($hash{dest} eq $hash{source}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hash{"dest"} eq $hash{"source"}) 0 0 0
59 0 die("Cannot filter '$hash{source}' onto itself.");
60 }
61  
62 0 ▶ while (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
63 0 $_ = shift;
64 0 ▶ if ($arg_options{$_}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($arg_options{$_}) { } 0 0 0
elsif ('CODE' eq ref $_) { } 0 0 0
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  
↑ Summary