lib/App/Greple/Filter.pm

filter: Statementstmt 81.7% 67 / 82 Branchbran 50.0% 19 / 38 Conditioncond 40.0% 4 / 10 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 100% 12 / 12 Podpod 0.0% 0 / 6 totaltotal 66.2% 102 / 154 CC 27 SCAR 25.2
CC
27
Cov
69%
push_input_filter
20.3
push_output_filter
19.6
get_filters
8.1
CRAP 12.4
« lib/App/Greple/select.pm ↑ Summary lib/App/Greple/Regions.pm »
1 package App::Greple::Filter;
2  
3 171 ▶use v5.24;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 171 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 171 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 171 our @EXPORT = ();
8 171 our %EXPORT_TAGS = ();
9 171 our @EXPORT_OK = qw();
10  
11 171 ▶use Getopt::EX::Func qw(parse_func);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 171 ▶use App::Greple::Common qw(%debug &FILELABEL);
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14  
15 166 ▶sub new {
Subroutine new: called CC=2 SCAR=7.0
Pod undocumented
16 166 my $class = shift;
17 166 my $obj = bless [], $class;
18  
19 166 ▶ $obj->append(@_) if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 166 166
20  
21 166 $obj;
22 }
23  
24 166 ▶sub parse {
Subroutine parse: called CC=2 SCAR=7.0
Pod undocumented
25 166 my $obj = shift;
26 166 ▶ push @$obj, map { /([^:]+):(.*)/ ? [ $1, $2 ] : $_ } @_;
Branch: 1 branch
BranchTrueFalseTotal
/([^:]+):(.*)/u ? : 0 2 2
27 166 $obj;
28 }
29  
30 166 ▶sub append {
Subroutine append: called CC=1 SCAR=0.0
Pod undocumented
31 166 my $obj = shift;
32 166 push @$obj, @_;
33 166 $obj;
34 }
35  
36 167 ▶sub get_filters {
Subroutine get_filters: called CC=7 SCAR=20.9
Pod undocumented
37 167 my $obj = shift;
38 167 my $filename = shift;
39  
40 167 my @f;
41 167 local $_ = $filename;
42 167 ▶ for (my $remember = ""; $remember ne $_; ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($remember ne $_) 167 167 334
43 167 $remember = $_;
44 167 for my $p (@$obj) {
45 670 ▶ if (ref $p eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $p eq 'ARRAY') { } 668 2 670
46 668 my($exp, $command) = @$p;
47 668 ▶ if (ref $exp eq 'CODE' ? &$exp : eval $exp) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $exp eq "CODE" ? &$exp : eval $exp) 0 668 668
ref $exp eq 'CODE' ? : 668 0 668
48 0 $command =~ s/{}/$filename/g;
49 0 push @f, $command;
50 0 ▶ last if $_ ne $remember;
Branch: 1 branch
BranchTrueFalseTotal
if $_ ne $remember 0 0 0
51 }
52 } else {
53 2 push @f, $p;
54 }
55 }
56 }
57 167 @f;
58 }
59  
60 171 ▶use POSIX();
Subroutine BEGIN: called CC=1 SCAR=0.0
61  
62 171 push @EXPORT, qw(push_output_filter);
63 7 ▶sub push_output_filter {
Subroutine push_output_filter: called CC=10 SCAR=29.7
Pod undocumented
64 7 ▶ my %arg = ref $_[0] eq 'HASH' ? %{+shift} : ();
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 5 2 7
65 7 my $fh = shift;
66 7 my $pkg = caller;
67 7 for my $filter (reverse @_) {
68 7 ▶ $debug{F} and warn "Push output Filter: \"$filter\"\n";
Branch: 1 branch
BranchTrueFalseTotal
$App::Greple::Filter::debug{"F"} and warn qq[Push output Filter: "$filter"\n] 0 7 7
69 7 ▶ my $pid = open($fh, '|-') // die "$filter: $!\n";
Condition50%1/2
open($fh, "|-") // die("${filter}: $!\n")
l!l
70
MC/DC0%0/1
open($fh, "|-") // die("${filter}: $!\n")
open($fh, "|-")
Truth table50%1/2
A
A= open($fh, "|-")
Aresult
11
00
70 7 ▶ if ($pid == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pid == 0) 3 4 7
71 3 ▶ if ($filter =~ /^&/ and
Branch: 1 branch
BranchTrueFalseTotal
if ($filter =~ /^&/u and my $f = parse_func({'PACKAGE', $pkg}, $filter)) { } 0 3 3
Condition33%1/3
$filter =~ /^&/u and my $f = parse_func({"PACKAGE", $pkg}, $filter)
!ll&&!rl&&r
300
MC/DC0%0/2
$filter =~ /^&/u and my $f = parse_func({"PACKAGE", $pkg}, $filter)
$filter =~ /^&/u my $f = parse_func({"PACKAGE", $pkg}, $filter)
Truth table33%1/3
A and B
A= $filter =~ /^&/uB= my $f = parse_func({"PACKAGE", $pkg}, $filter)
ABresult
0X0
100
111
72 my $f = parse_func({ PACKAGE => $pkg }, $filter)) {
73 0 local @ARGV;
74 0 ▶ open STDIN, '<&', 0 if eof STDIN;
Branch: 1 branch
BranchTrueFalseTotal
if eof STDIN 0 0 0
75 0 $f->call;
76 } else {
77 3 do { exec $filter } ;
78 0 ▶ warn $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
79 }
80 0 STDOUT->flush();
81 0 STDERR->flush();
82 0 POSIX::_exit(0);
83 }
84 }
85 }
86  
87 171 push @EXPORT, qw(push_input_filter);
88 2 ▶sub push_input_filter {
Subroutine push_input_filter: called CC=10 SCAR=30.1
Pod undocumented
89 2 ▶ my %arg = ref $_[0] eq 'HASH' ? %{+shift} : ();
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 2 0 2
90 2 my $pkg = caller;
91 2 for my $filter (@_) {
92 2 ▶ $debug{F} and warn "Push input Filter: \"$filter\"\n";
Branch: 1 branch
BranchTrueFalseTotal
$App::Greple::Filter::debug{"F"} and warn qq[Push input Filter: "$filter"\n] 0 2 2
93 2 ▶ if ($filter =~ /^&/ and
Branch: 1 branch
BranchTrueFalseTotal
if ($filter =~ /^&/u and my $f = parse_func({'PACKAGE', $pkg}, $filter)) { } 0 2 2
Condition33%1/3
$filter =~ /^&/u and my $f = parse_func({"PACKAGE", $pkg}, $filter)
!ll&&!rl&&r
200
MC/DC0%0/2
$filter =~ /^&/u and my $f = parse_func({"PACKAGE", $pkg}, $filter)
$filter =~ /^&/u my $f = parse_func({"PACKAGE", $pkg}, $filter)
Truth table33%1/3
A and B
A= $filter =~ /^&/uB= my $f = parse_func({"PACKAGE", $pkg}, $filter)
ABresult
0X0
100
111
94 my $f = parse_func({ PACKAGE => $pkg }, $filter)) {
95 0 ▶ if ($arg{&FILELABEL}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg{&FILELABEL}) 0 0 0
96 0 $f->append(&FILELABEL => $arg{&FILELABEL});
97 }
98 ##
99 ## intput filter function is responsible for process fork
100 ##
101 0 $f->call;
102 } else {
103 2 ▶ my $pid = open(STDIN, '-|') // die "$filter: $!\n";
Condition50%1/2
open(STDIN, "-|") // die("${filter}: $!\n")
l!l
20
MC/DC0%0/1
open(STDIN, "-|") // die("${filter}: $!\n")
open(STDIN, "-|")
Truth table50%1/2
A
A= open(STDIN, "-|")
Aresult
11
00
104 2 ▶ if ($pid == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pid == 0) 1 1 2
105 1 do { exec $filter } ;
106 0 ▶ warn $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
107 0 POSIX::_exit(0);
108 }
109 }
110 }
111 }
112  
113 171 1;
« lib/App/Greple/select.pm ↑ Summary lib/App/Greple/Regions.pm »