| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 43 | 167 | $remember = $_; | |||||||||||||||||||||||||||
| 44 | 167 | for my $p (@$obj) { | |||||||||||||||||||||||||||
| 45 | 670 | ▶ | if (ref $p eq 'ARRAY') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 668 | my($exp, $command) = @$p; | |||||||||||||||||||||||||||
| 47 | 668 | ▶ | if (ref $exp eq 'CODE' ? &$exp : eval $exp) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 48 | 0 | $command =~ s/{}/$filename/g; | |||||||||||||||||||||||||||
| 49 | 0 | push @f, $command; | |||||||||||||||||||||||||||
| 50 | 0 | ▶ | last if $_ ne $remember; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 69 | 7 | ▶ | my $pid = open($fh, '|-') // die "$filter: $!\n"; | ||||||||||||||||||||||||||
|
Condition50%1/2
open($fh, "|-") // die("${filter}: $!\n")
MC/DC0%0/1
open($fh, "|-") // die("${filter}: $!\n")
open($fh, "|-")
Truth table50%1/2
A
A= open($fh, "|-")
| |||||||||||||||||||||||||||||
| 70 | 7 | ▶ | if ($pid == 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | 3 | ▶ | if ($filter =~ /^&/ and | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$filter =~ /^&/u and my $f = parse_func({"PACKAGE", $pkg}, $filter)
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)
| |||||||||||||||||||||||||||||
| 72 | my $f = parse_func({ PACKAGE => $pkg }, $filter)) { | ||||||||||||||||||||||||||||
| 73 | 0 | local @ARGV; | |||||||||||||||||||||||||||
| 74 | 0 | ▶ | open STDIN, '<&', 0 if eof STDIN; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | 0 | $f->call; | |||||||||||||||||||||||||||
| 76 | } else { | ||||||||||||||||||||||||||||
| 77 | 3 | do { exec $filter } ; | |||||||||||||||||||||||||||
| 78 | 0 | ▶ | warn $@ if $@; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 90 | 2 | my $pkg = caller; | |||||||||||||||||||||||||||
| 91 | 2 | for my $filter (@_) { | |||||||||||||||||||||||||||
| 92 | 2 | ▶ | $debug{F} and warn "Push input Filter: \"$filter\"\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | 2 | ▶ | if ($filter =~ /^&/ and | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$filter =~ /^&/u and my $f = parse_func({"PACKAGE", $pkg}, $filter)
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)
| |||||||||||||||||||||||||||||
| 94 | my $f = parse_func({ PACKAGE => $pkg }, $filter)) { | ||||||||||||||||||||||||||||
| 95 | 0 | ▶ | if ($arg{&FILELABEL}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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")
MC/DC0%0/1
open(STDIN, "-|") // die("${filter}: $!\n")
open(STDIN, "-|")
Truth table50%1/2
A
A= open(STDIN, "-|")
| |||||||||||||||||||||||||||||
| 104 | 2 | ▶ | if ($pid == 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 105 | 1 | do { exec $filter } ; | |||||||||||||||||||||||||||
| 106 | 0 | ▶ | warn $@ if $@; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 107 | 0 | POSIX::_exit(0); | |||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 171 | 1; | |||||||||||||||||||||||||||