blib/lib/IPC/PrettyPipe.pm

filter: Statementstmt 95.1% 198 / 208 Branchbran 65.3% 51 / 78 Conditioncond 77.2% 17 / 22 MC/DCmcdc 25.0% 3 / 12 Subroutinesub 98.0% 49 / 50 Podpod 81.8% 9 / 11 totaltotal 85.8% 327 / 381 CC 54 SCAR 17.2
CC
54
Cov
86%
add
12.8
valsubst
12.5
ffadd
11.1
CRAP 5.6
« blib/lib/IPC/PrettyPipe/Cmd.pm ↑ Summary blib/lib/IPC/PrettyPipe/Stream.pm »
1 package IPC::PrettyPipe;
2  
3 # ABSTRACT: manage human readable external command execution pipelines
4  
5 17 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 17 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 17 our $VERSION = '0.13';
9 17 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 17 ▶use List::Util qw[ sum ];
Subroutine BEGIN: called CC=1 SCAR=0.0
12 17 ▶use Module::Load qw[ load ];
Subroutine BEGIN: called CC=1 SCAR=0.0
13 use Module::Runtime
14 17 ▶ qw[ check_module_name compose_module_name use_package_optimistically ];
Subroutine BEGIN: called CC=1 SCAR=0.0
15 17 ▶use Safe::Isa;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 17 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 17 ▶use Types::Standard -all;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 17 ▶use Type::Params qw[ validate ];
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 17 ▶use IPC::PrettyPipe::Types -all;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 17 ▶use IPC::PrettyPipe::Cmd;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 17 ▶use IPC::PrettyPipe::Queue;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 17 ▶use IPC::PrettyPipe::Arg::Format;
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 17 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 17 ▶use Moo::Role ();
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 17 with 'IPC::PrettyPipe::Queue::Element';
31  
32 17 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
33  
34 17 ▶use overload 'fallback' => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51 17 ▶use overload '|=' => sub {
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
52 2 $_[0]->add( $_[1] );
53 2 return $_[0];
54 17 };
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76 17 ▶use overload '|' => sub {
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=3 SCAR=11.1
77 3 my $swap = pop;
78 3 my $pipe = IPC::PrettyPipe->new;
79 3 ▶ $pipe->add( $_ ) for ( $swap ? reverse( @_ ) : @_ );
Branch: 1 branch
BranchTrueFalseTotal
$swap ? : 0 3 3
80 3 $pipe;
81 17 };
82  
83  
84 17 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
85 17 ▶ IPC::PrettyPipe::Arg::Format->shadow_attrs( fmt => sub { 'arg' . shift } );
Subroutine __ANON__: called CC=1 SCAR=0.0
86 }
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115 has argfmt => (
116 is => 'ro',
117 lazy => 1,
118 handles => IPC::PrettyPipe::Arg::Format->shadowed_attrs,
119 20 ▶ default => sub { IPC::PrettyPipe::Arg::Format->new_from_attrs( shift ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
120 17 );
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
138  
139  
140  
141  
142  
143  
144  
145  
146  
147  
148 has streams => (
149 is => 'lazy',
150 65 ▶ default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
151 65 IPC::PrettyPipe::Queue->new( elements => $_[0]->_init_streams );
152 },
153 17 init_arg => undef,
154 );
155  
156  
157 has _init_streams => (
158 is => 'ro',
159 isa => ArrayRef [ InstanceOf ['IPC::PrettyPipe::Stream'] ],
160 init_arg => 'streams',
161 108 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
162 17 );
163  
164 has _init_cmds => (
165 is => 'ro',
166 init_arg => 'cmds',
167 coerce => AutoArrayRef->coercion,
168 isa => ArrayRef,
169 108 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
170 17 predicate => 1,
171 clearer => 1,
172 );
173  
174  
175  
176  
177  
178  
179  
180  
181  
182  
183  
184  
185  
186  
187  
188  
189  
190  
191 # must delay building cmds until all attributes have been specified
192 has cmds => (
193 is => 'ro',
194 110 ▶ default => sub { IPC::PrettyPipe::Queue->new },
Subroutine __ANON__: called CC=1 SCAR=0.0
195 17 init_arg => undef,
196 );
197  
198  
199  
200  
201  
202  
203  
204  
205  
206  
207  
208 17 has merge_pipes => (
209 is => 'rw',
210 default => 1,
211 isa => Bool,
212 );
213  
214 has _executor_arg => (
215 is => 'rw',
216 init_arg => 'executor',
217 106 ▶ default => sub { 'IPC::Run' },
Subroutine __ANON__: called CC=1 SCAR=0.0
218 9 ▶ trigger => sub { $_[0]->_clear_executor },
Subroutine __ANON__: called CC=1 SCAR=0.0
219 17 );
220  
221  
222 has _executor => (
223 is => 'rw',
224 isa => ConsumerOf ['IPC::PrettyPipe::Executor'],
225 lazy => 1,
226 clearer => 1,
227 11 ▶ default => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
228  
229 11 my $backend = $_[0]->_executor_arg;
230  
231 ## no critic (ProhibitAccessOfPrivateData)
232 11 ▶ return $backend->$_does( 'IPC::PrettyPipe::Executor' )
Branch: 1 branch
BranchTrueFalseTotal
$backend->$IPC::PrettyPipe::_does('IPC::PrettyPipe::Executor') ? : 1 10 11
233 ? $backend
234 : $_[0]->_backend_factory( Execute => $backend );
235 },
236 17 );
237  
238  
239  
240  
241  
242  
243  
244  
245  
246  
247  
248 10 ▶sub executor {
Subroutine executor: called CC=2 SCAR=6.9
Pod documented
249 10 my $self = shift;
250  
251 10 ▶ $self->_executor_arg( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if @_ 5 5 10
252 if @_;
253  
254 10 return $self->_executor;
255 }
256  
257  
258  
259  
260  
261  
262  
263  
264  
265 6 ▶sub run {
Subroutine run: called CC=1 SCAR=0.0
Pod documented
266 6 my ( $self ) = @_;
267  
268 6 $self->_executor->run( $self );
269 }
270  
271  
272 has _renderer_arg => (
273 is => 'rw',
274 init_arg => 'renderer',
275 106 ▶ default => sub { 'Template::Tiny' },
Subroutine __ANON__: called CC=1 SCAR=0.0
276 47 ▶ trigger => sub { $_[0]->_clear_renderer },
Subroutine __ANON__: called CC=1 SCAR=0.0
277 17 );
278  
279 has _renderer => (
280 is => 'rw',
281 isa => ConsumerOf ['IPC::PrettyPipe::Renderer'],
282 lazy => 1,
283 clearer => 1,
284 52 ▶ default => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
285  
286 52 my $backend = $_[0]->_renderer_arg;
287  
288 ## no critic (ProhibitAccessOfPrivateData)
289 52 ▶ return $backend->$_does( 'IPC::PrettyPipe::Renderer' )
Branch: 1 branch
BranchTrueFalseTotal
$backend->$IPC::PrettyPipe::_does('IPC::PrettyPipe::Renderer') ? : 22 30 52
290 ? $backend
291 : $_[0]->_backend_factory( Render => $backend );
292 },
293 17 );
294  
295  
296  
297  
298  
299  
300  
301  
302  
303  
304  
305  
306  
307  
308  
309  
310  
311  
312  
313 53 ▶sub renderer {
Subroutine renderer: called CC=2 SCAR=6.9
Pod documented
314 53 my $self = shift;
315  
316 53 ▶ $self->_renderer_arg( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if @_ 43 10 53
317 if @_;
318  
319 53 return $self->_renderer;
320 }
321  
322  
323  
324  
325  
326  
327  
328  
329  
330 42 ▶sub render {
Subroutine render: called CC=1 SCAR=0.0
Pod documented
331  
332 42 my $self = shift;
333  
334 42 $self->_renderer()->render( $self );
335 }
336  
337  
338  
339  
340  
341  
342 # accept:
343 # new( \%hash )
344 # new( $cmd )
345 # new( @stuff )
346 110 ▶sub BUILDARGS {
Subroutine BUILDARGS: called CC=3 SCAR=14.2
Pod undocumented
347  
348 110 shift;
349  
350 return
351 110 ▶ @_ == 1
Branch: 2 branches
BranchTrueFalseTotal
@_ == 1 ? : 0 110 110
'HASH' eq ref $_[0] ? : 0 0 0
352 ? 'HASH' eq ref( $_[0] )
353 ? $_[0]
354 : { cmds => $_[0] }
355 : {@_};
356  
357 }
358  
359  
360 110 ▶sub BUILD {
Subroutine BUILD: called CC=2 SCAR=7.0
Pod undocumented
361  
362 110 my $self = shift;
363  
364 110 ▶ if ( $self->_has_init_cmds ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_has_init_cmds) 110 0 110
365  
366 110 $self->ffadd( @{ $self->_init_cmds } );
367 110 $self->_clear_init_cmds;
368 }
369  
370 110 return;
371  
372 }
373  
374  
375  
376  
377  
378  
379  
380  
381  
382  
383  
384  
385  
386  
387  
388  
389  
390  
391  
392  
393  
394  
395  
396  
397  
398  
399  
400  
401  
402  
403  
404  
405  
406  
407  
408 139 ▶sub add {
Subroutine add: called CC=11 SCAR=25.5
Pod documented
409  
410 139 my $self = shift;
411  
412 139 ▶ unshift @_, 'cmd' if @_ == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 1 139 0 139
413  
414 ## no critic (ProhibitAccessOfPrivateData)
415  
416 139 my $argfmt = $self->argfmt->clone;
417  
418 139 my $argfmt_attrs = IPC::PrettyPipe::Arg::Format->shadowed_attrs;
419  
420 my ( $attr ) = validate(
421 \@_,
422 slurpy Dict [
423 cmd => Str | Cmd | Pipe,
424 args => Optional,
425 argfmt => Optional [ InstanceOf ['IPC::PrettyPipe::Arg::Format'] ],
426 139 ( map { $_ => Optional [Str] } keys %{$argfmt_attrs} ),
427 ] );
428  
429  
430 139 ▶ $argfmt->copy_from( $attr->{argfmt} ) if defined $attr->{argfmt};
Branch: 1 branch
BranchTrueFalseTotal
if defined $attr->{"argfmt"} 0 139 139
431 139 $argfmt->copy_from( IPC::PrettyPipe::Arg::Format->new_from_hash( $attr ) );
432  
433  
434 139 ▶ if ( $attr->{cmd}->$_isa( 'IPC::PrettyPipe::Cmd' ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($attr->{'cmd'}->$IPC::PrettyPipe::_isa('IPC::PrettyPipe::Cmd')) { } 123 16 139
elsif ($attr->{'cmd'}->$IPC::PrettyPipe::_isa('IPC::PrettyPipe')) { } 16 0 16
435  
436 123 my $cmd = delete $attr->{cmd};
437  
438 123 ▶ croak(
Branch: 1 branch
BranchTrueFalseTotal
if keys %$attr 0 123 123
439 "cannot specify additional arguments when passing a Cmd object\n" )
440 if keys %$attr;
441  
442 123 $self->cmds->push( $cmd );
443  
444 123 return $cmd;
445 }
446  
447 elsif ( $attr->{cmd}->$_isa( 'IPC::PrettyPipe' ) ) {
448  
449 16 my $cmd = delete $attr->{cmd};
450  
451 16 ▶ croak(
Branch: 1 branch
BranchTrueFalseTotal
if keys %$attr 0 16 16
452 "cannot specify additional arguments when passing a Pipe object\n" )
453 if keys %$attr;
454  
455 16 ▶ if ( $self->merge_pipes && $cmd->streams->empty ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->merge_pipes and $cmd->streams->empty) { } 11 5 16
Condition100%3/3
$self->merge_pipes and $cmd->streams->empty
!ll&&!rl&&r
2311
MC/DC100%2/2
$self->merge_pipes and $cmd->streams->empty
$self->merge_pipes $cmd->streams->empty
Truth table100%3/3
A and B
A= $self->merge_pipesB= $cmd->streams->empty
ABresult
0X0
100
111
456 11 $self->cmds->push( $_ ) foreach @{ $cmd->cmds->elements };
457 11 return $self;
458 }
459 else {
460  
461 5 $self->cmds->push( $cmd );
462 5 return $cmd;
463 }
464 }
465  
466 else {
467  
468 my $cmd = IPC::PrettyPipe::Cmd->new(
469 cmd => $attr->{cmd},
470 argfmt => $argfmt->clone,
471 0 ▶ exists $attr->{args} ? ( args => $attr->{args} ) : (),
Branch: 1 branch
BranchTrueFalseTotal
exists $attr->{'args'} ? : 0 0 0
472 );
473  
474 0 $self->cmds->push( $cmd );
475  
476 0 return $cmd;
477  
478 }
479  
480 0 die( "NOTREACHED" );
481 }
482  
483  
484  
485  
486  
487  
488  
489  
490  
491  
492  
493  
494  
495  
496  
497  
498  
499  
500  
501  
502  
503  
504  
505  
506  
507  
508  
509  
510  
511  
512  
513  
514  
515  
516  
517  
518  
519  
520  
521  
522  
523  
524 200 ▶sub ffadd {
Subroutine ffadd: called CC=10 SCAR=24.1
Pod documented
525  
526 200 my $self = shift;
527 200 my @args = @_;
528  
529 200 my $argfmt = $self->argfmt->clone;
530  
531 200 ▶ for ( my $idx = 0 ; $idx < @args ; $idx++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($idx < @args) 143 200 343
532  
533 143 my $t = $args[$idx];
534  
535 143 ▶ if ( $t->$_isa( 'IPC::PrettyPipe::Arg::Format' ) ) {
Branch: 6 branches
BranchTrueFalseTotal
if ($t->$IPC::PrettyPipe::_isa('IPC::PrettyPipe::Arg::Format')) { } 4 139 143
elsif ($t->$IPC::PrettyPipe::_isa('IPC::PrettyPipe::Cmd')) { } 10 129 139
elsif ($t->$IPC::PrettyPipe::_isa('IPC::PrettyPipe')) { } 6 123 129
elsif ('ARRAY' eq ref $t) { } 109 14 123
elsif ($t->$IPC::PrettyPipe::_isa('IPC::PrettyPipe::Stream')) { } 0 14 14
elsif (not ref $t) { } 14 0 14
536  
537 4 $t->copy_into( $argfmt );
538  
539 }
540  
541 elsif ( $t->$_isa( 'IPC::PrettyPipe::Cmd' ) ) {
542  
543 10 $self->add( $t );
544  
545 }
546  
547 elsif ( $t->$_isa( 'IPC::PrettyPipe' ) ) {
548  
549 6 $self->add( $t );
550  
551 }
552  
553 elsif ( 'ARRAY' eq ref $t ) {
554  
555 109 my $cmd;
556  
557 109 ▶ if ( ( $cmd = $t->[0] )->$_isa( 'IPC::PrettyPipe' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (($cmd = $t->[0])->$IPC::PrettyPipe::_isa('IPC::PrettyPipe')) { } 3 106 109
558 3 ▶ croak(
Branch: 1 branch
BranchTrueFalseTotal
if @$t > 1 0 3 3
559 "In an array containing an IPC::PrettyPipe object, it must be the only element\n"
560 ) if @$t > 1;
561 }
562  
563 else {
564  
565 106 $cmd = IPC::PrettyPipe::Cmd->new(
566 cmd => shift( @$t ),
567 argfmt => $argfmt->clone
568 );
569 106 $cmd->ffadd( @$t );
570 }
571  
572 109 $self->add( $cmd );
573 }
574  
575 elsif ( $t->$_isa( 'IPC::PrettyPipe::Stream' ) ) {
576  
577 0 $self->stream( $t );
578  
579 }
580  
581 elsif ( !ref $t ) {
582  
583 14 ▶ try {
Subroutine __ANON__: called CC=3 SCAR=11.3
584  
585 14 my $stream = IPC::PrettyPipe::Stream->new(
586 spec => $t,
587 strict => 0,
588 );
589  
590 14 ▶ if ( $stream->requires_file ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stream->requires_file) 14 0 14
591  
592 14 ▶ croak( "arg[$idx]: stream operator $t requires a file\n" )
Branch: 1 branch
BranchTrueFalseTotal
if ++$idx == @args 0 14 14
593 if ++$idx == @args;
594  
595 14 $stream->file( $args[$idx] );
596 }
597  
598 14 $self->stream( $stream );
599 }
600 0 ▶ catch {
Subroutine __ANON__: not called CC=2 SCAR=17.9
601  
602 0 ▶ die $_ unless /requires a file|cannot parse/;
Branch: 1 branch
BranchTrueFalseTotal
unless /requires a file|cannot parse/ 0 0 0
603  
604 # This is the "fall through" which takes care
605 # of calling with a simple string argument, which is
606 # taken to be a command to run. It probably shouldn't
607 # be buried at this level of the code.
608  
609 0 $self->add( cmd => $t, argfmt => $argfmt );
610 14 };
611  
612 }
613  
614 else {
615  
616 0 croak( "arg[$idx]: unrecognized parameter to ffadd\n" );
617  
618 }
619  
620 }
621  
622 }
623  
624  
625  
626  
627  
628  
629  
630  
631  
632  
633  
634  
635 14 ▶sub stream {
Subroutine stream: called CC=5 SCAR=20.9
Pod documented
636  
637 14 my $self = shift;
638  
639 14 my $spec = shift;
640  
641 14 ▶ if ( $spec->$_isa( 'IPC::PrettyPipe::Stream' ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($spec->$IPC::PrettyPipe::_isa('IPC::PrettyPipe::Stream')) { } 14 0 14
elsif (not ref $spec) { } 0 0 0
642  
643 14 ▶ croak( "too many arguments\n" )
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 14 14
644 if @_;
645  
646 14 $self->streams->push( $spec );
647  
648 }
649  
650 elsif ( !ref $spec ) {
651  
652 0 ▶ $self->streams->push(
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
653 IPC::PrettyPipe::Stream->new(
654 spec => $spec,
655 +@_ ? ( file => @_ ) : () ) );
656 }
657  
658 else {
659  
660 0 croak( "illegal stream specification\n" );
661  
662 }
663  
664  
665 14 return;
666 }
667  
668  
669  
670  
671  
672  
673  
674  
675  
676  
677  
678  
679 16 ▶sub valmatch {
Subroutine valmatch: called CC=3 SCAR=11.0
Pod documented
680  
681 16 my $self = shift;
682 16 my $pattern = shift;
683  
684 return sum 0,
685 16 ▶ map { $_->valmatch( $pattern ) && 1 || 0 } @{ $self->cmds->elements };
Condition100%4/4
$_->valmatch($pattern) && 1 || 0
l!l
242
$_->valmatch($pattern) and 1
!ll
224
MC/DC100%1/1
$_->valmatch($pattern) && 1 || 0
$_->valmatch($pattern)
Truth table100%2/2
A
A= $_->valmatch($pattern)
Aresult
11
00
686 }
687  
688  
689  
690  
691  
692  
693  
694  
695  
696  
697  
698  
699  
700  
701  
702  
703  
704  
705  
706  
707  
708  
709  
710  
711  
712  
713  
714  
715  
716  
717  
718  
719  
720  
721  
722  
723  
724  
725  
726  
727  
728  
729  
730  
731  
732  
733  
734  
735  
736  
737  
738  
739  
740  
741  
742  
743  
744  
745  
746  
747  
748  
749  
750  
751  
752  
753  
754  
755  
756  
757 12 ▶sub valsubst {
Subroutine valsubst: called CC=12 SCAR=25.3
Pod documented
758  
759 12 my $self = shift;
760  
761 12 ▶ my @args = ( shift, shift, @_ > 1 ? {@_} : @_ );
Branch: 1 branch
BranchTrueFalseTotal
@_ > 1 ? : 8 4 12
762  
763 12 my ( $pattern, $value, $args ) = validate(
764 \@args,
765 RegexpRef,
766 Str,
767 Optional [
768 Dict [
769 lastvalue => Optional [Str],
770 firstvalue => Optional [Str] ]
771 ],
772 );
773  
774 12 my $nmatch = $self->valmatch( $pattern );
775  
776 12 ▶ if ( $nmatch == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nmatch == 1) { } 5 7 12
777  
778 ## no critic (ProhibitAccessOfPrivateData)
779 5 ▶ $args->{lastvalue} //= $args->{firstvalue} // $value;
Condition66%4/6
$args->{"lastvalue"} //= $args->{"firstvalue"} // $value
l!l&&r!l&&!r
230
$args->{"firstvalue"} // $value
l!l&&r!l&&!r
120
MC/DC0%0/3
$args->{"lastvalue"} //= $args->{"firstvalue"} // $value
$args->{"lastvalue"} $args->{"firstvalue"} $value
Truth table0%0/4
A //= B // C
A= $args->{"lastvalue"}B= $args->{"firstvalue"}C= $value
ABCresult
1XX1
01X1
0011
0000
780 5 ▶ $args->{firstvalue} //= $args->{lastvalue};
Condition66%2/3
$args->{"firstvalue"} //= $args->{"lastvalue"}
l!l&&r!l&&!r
140
MC/DC0%0/2
$args->{"firstvalue"} //= $args->{"lastvalue"}
$args->{"firstvalue"} $args->{"lastvalue"}
Truth table66%2/3
A //= B
A= $args->{"firstvalue"}B= $args->{"lastvalue"}
ABresult
1X1
011
000
781  
782 }
783 else {
784  
785 ## no critic (ProhibitAccessOfPrivateData)
786 7 ▶ $args->{lastvalue} ||= $value;
Condition66%2/3
$args->{"lastvalue"} ||= $value
l!l&&r!l&&!r
430
MC/DC0%0/2
$args->{"lastvalue"} ||= $value
$args->{"lastvalue"} $value
Truth table66%2/3
A ||= B
A= $args->{"lastvalue"}B= $value
ABresult
1X1
011
000
787 7 ▶ $args->{firstvalue} ||= $value;
Condition66%2/3
$args->{"firstvalue"} ||= $value
l!l&&r!l&&!r
430
MC/DC0%0/2
$args->{"firstvalue"} ||= $value
$args->{"firstvalue"} $value
Truth table66%2/3
A ||= B
A= $args->{"firstvalue"}B= $value
ABresult
1X1
011
000
788 }
789  
790 12 my $match = 0;
791 12 foreach ( @{ $self->cmds->elements } ) {
792  
793 ## no critic (ProhibitAccessOfPrivateData)
794  
795 $match++
796 if $_->valsubst( $pattern,
797 $match == 0 ? $args->{firstvalue}
798 : $match == ( $nmatch - 1 ) ? $args->{lastvalue}
799 22 ▶ : $value );
Branch: 3 branches
BranchTrueFalseTotal
if $_->valsubst($pattern, $match == 0 ? $args->{"firstvalue"} : ($match == $nmatch - 1 ? $args->{"lastvalue"} : $value)) 22 0 22
$match == 0 ? : 12 10 22
$match == $nmatch - 1 ? : 7 3 10
800 }
801  
802 12 return $match;
803 }
804  
805 40 ▶sub _backend_factory {
Subroutine _backend_factory: called CC=4 SCAR=13.9
806  
807 40 my ( $self, $type, $req ) = ( shift, shift, shift );
808  
809 40 check_module_name( $req );
810  
811 my $role = compose_module_name( __PACKAGE__,
812 {
813 Render => 'Renderer',
814 Execute => 'Executor'
815 40 }->{$type} );
816  
817 40 my $module;
818  
819 40 for my $try ( $req, compose_module_name( "IPC::PrettyPipe::$type", $req ) )
820 {
821 76 ▶ next unless use_package_optimistically( $try )->DOES( $role );
Branch: 1 branch
BranchTrueFalseTotal
unless &use_package_optimistically($try)->DOES($role) 36 40 76
822  
823 40 $module = $try;
824 40 last;
825 }
826  
827 croak(
828 40 ▶ "requested $type module ($req) either doesn't exist or doesn't consume $role\n"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $module 0 40 40
829 ) if !defined $module;
830  
831 40 return $module->new( @_ );
832 }
833  
834  
835 6 ▶sub _storefh {
Subroutine _storefh: called CC=3 SCAR=11.0
836  
837 6 my $self = shift;
838  
839 6 my $sfh = IO::ReStoreFH->new;
840  
841 6 for my $stream ( @{ $self->streams->elements } ) {
842  
843 4 my ( $sub, @fh ) = $stream->apply;
844  
845 4 $sfh->store( $_ ) foreach @fh;
846  
847 4 $sub->();
848 }
849  
850 6 return $sfh;
851 }
852  
853 17 1;
854  
855 #
856 # This file is part of IPC-PrettyPipe
857 #
858 # This software is Copyright (c) 2018 by Smithsonian Astrophysical Observatory.
859 #
860 # This is free software, licensed under:
861 #
862 # The GNU General Public License, Version 3, June 2007
863 #
864  
865 __END__
« blib/lib/IPC/PrettyPipe/Cmd.pm ↑ Summary blib/lib/IPC/PrettyPipe/Stream.pm »