blib/lib/IPC/PrettyPipe/Arg.pm

filter: Statementstmt 92.9% 53 / 57 Branchbran 78.5% 11 / 14 Conditioncond 50.0% 6 / 12 MC/DCmcdc 50.0% 4 / 8 Subroutinesub 93.3% 14 / 15 Podpod 85.7% 6 / 7 totaltotal 83.1% 94 / 113 CC 12 SCAR 13.3
CC
12
Cov
84%
BUILDARGS
9.4
has_blank_value
6.0
render
4.0
CRAP 3.8
« blib/lib/IPC/PrettyPipe/Stream/Utils.pm ↑ Summary blib/lib/IPC/PrettyPipe/Execute/IPC/Run.pm »
1 package IPC::PrettyPipe::Arg;
2  
3 # ABSTRACT: An argument to an IPC::PrettyPipe::Cmd command
4  
5 24 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 24 ▶use String::ShellQuote;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 24 ▶use Types::Standard qw[ Str ];
Subroutine BEGIN: called CC=1 SCAR=0.0
10 24 ▶use IPC::PrettyPipe::Arg::Format;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 24 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 24 our $VERSION = '0.13';
15  
16 24 has name => (
17 is => 'ro',
18 isa => Str,
19 required => 1,
20 );
21  
22 24 has value => (
23 is => 'rwp',
24 isa => Str,
25 predicate => 1,
26 );
27  
28 24 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30  
31 24 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 24 IPC::PrettyPipe::Arg::Format->shadow_attrs;
34  
35 }
36  
37 24 with 'MooX::Attributes::Shadow::Role';
38  
39  
40 shadowable_attrs( 'fmt',
41 24 values %{ IPC::PrettyPipe::Arg::Format->shadowed_attrs } );
42  
43 24 with 'IPC::PrettyPipe::Queue::Element';
44  
45 has fmt => (
46 is => 'ro',
47 lazy => 1,
48 24 handles => [ keys %{ IPC::PrettyPipe::Arg::Format->shadowed_attrs } ],
49 10 ▶ default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
50 10 IPC::PrettyPipe::Arg::Format->new_from_attrs( shift );
51 },
52 24 );
53  
54  
55  
56  
57  
58  
59 # accept full attribute interface, or
60 # new( name );
61 # new( [ name, value ] );
62  
63 235 ▶sub BUILDARGS {
Subroutine BUILDARGS: called CC=5 SCAR=22.5
Pod undocumented
64  
65 235 my $class = shift;
66  
67 235 ▶ if ( @_ == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1) 10 225 235
68  
69 10 ▶ return $_[0] if 'HASH' eq ref( $_[0] );
Branch: 1 branch
BranchTrueFalseTotal
if "HASH" eq ref $_[0] 10 0 10
70  
71 return { name => $_[0][0], value => $_[0][1] }
72 0 ▶ if 'ARRAY' eq ref( $_[0] ) && @{ $_[0] } == 2;
Branch: 1 branch
BranchTrueFalseTotal
if "ARRAY" eq ref $_[0] and @{$_[0];} == 2 0 0 0
Condition0%0/3
"ARRAY" eq ref $_[0] and @{$_[0];} == 2
!ll&&!rl&&r
000
MC/DC0%0/2
"ARRAY" eq ref $_[0] and @{$_[0];} == 2
"ARRAY" eq ref $_[0] @{$_[0];} == 2
Truth table0%0/3
A and B
A= "ARRAY" eq ref $_[0]B= @{$_[0];} == 2
ABresult
0X0
100
111
73  
74 0 return { name => $_[0] };
75  
76 }
77  
78 225 return {@_};
79 }
80  
81 25 ▶sub quoted_name { shell_quote( $_[0]->name ) }
Subroutine quoted_name: called CC=1 SCAR=0.0
Pod documented
82  
83 6 ▶sub quoted_value { shell_quote( $_[0]->value ) }
Subroutine quoted_value: called CC=1 SCAR=0.0
Pod documented
84  
85  
86 # for render templates
87 0 ▶sub has_blank_value {
Subroutine has_blank_value: not called CC=2 SCAR=17.9
Pod documented
88  
89 0 ▶ return $_[0]->has_value && $_[0]->value eq '';
Condition0%0/3
$_[0]->has_value && $_[0]->value eq ''
!ll&&!rl&&r
000
MC/DC0%0/2
$_[0]->has_value && $_[0]->value eq ''
$_[0]->has_value $_[0]->value eq ''
Truth table0%0/3
A && B
A= $_[0]->has_valueB= $_[0]->value eq ''
ABresult
0X0
100
111
90  
91 }
92  
93 111 ▶sub render {
Subroutine render: called CC=4 SCAR=13.9
Pod documented
94  
95 111 my $self = shift;
96  
97 111 my $fmt = $self->fmt;
98  
99 111 ▶ my $name = ( $fmt->has_pfx ? $fmt->pfx : '' ) . $self->name;
Branch: 1 branch
BranchTrueFalseTotal
$fmt->has_pfx ? : 7 104 111
100  
101 111 ▶ if ( $self->has_value ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_value) { } 14 97 111
102  
103 14 ▶ if ( $fmt->has_sep ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fmt->has_sep) { } 7 7 14
104  
105 7 return join( '', $name, $fmt->sep, $self->value );
106  
107 }
108 else {
109  
110 7 return $name, $self->value;
111 }
112 }
113  
114 else {
115  
116 97 return $name;
117 }
118  
119 }
120  
121 107 ▶sub valmatch {
Subroutine valmatch: called CC=2 SCAR=6.9
Pod documented
122  
123 107 my $self = shift;
124 107 my $pattern = shift;
125  
126 107 ▶ return $self->has_value && $self->value =~ /$pattern/;
Condition100%3/3
$self->has_value && $self->value =~ /$pattern/
!ll&&!rl&&r
31103
MC/DC100%2/2
$self->has_value && $self->value =~ /$pattern/
$self->has_value $self->value =~ /$pattern/
Truth table100%3/3
A && B
A= $self->has_valueB= $self->value =~ /$pattern/
ABresult
0X0
100
111
127 }
128  
129 58 ▶sub valsubst {
Subroutine valsubst: called CC=3 SCAR=11.0
Pod documented
130  
131 58 my $self = shift;
132  
133 58 my ( $pattern, $rep ) = @_;
134  
135 58 ▶ if ( $self->has_value && ( my $value = $self->value ) =~ s/$pattern/$rep/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_value and (my $value = $self->value) =~ s/$pattern/$rep/) 44 14 58
Condition100%3/3
$self->has_value and (my $value = $self->value) =~ s/$pattern/$rep/
!ll&&!rl&&r
11344
MC/DC100%2/2
$self->has_value and (my $value = $self->value) =~ s/$pattern/$rep/
$self->has_value (my $value = $self->value) =~ s/$pattern/$rep/
Truth table100%3/3
A and B
A= $self->has_valueB= (my $value = $self->value) =~ s/$pattern/$rep/
ABresult
0X0
100
111
136 {
137  
138 44 $self->_set_value( $value );
139  
140 44 return 1;
141  
142 }
143  
144 14 return 0;
145 }
146  
147 24 1;
148  
149 #
150 # This file is part of IPC-PrettyPipe
151 #
152 # This software is Copyright (c) 2018 by Smithsonian Astrophysical Observatory.
153 #
154 # This is free software, licensed under:
155 #
156 # The GNU General Public License, Version 3, June 2007
157 #
158  
159 __END__
« blib/lib/IPC/PrettyPipe/Stream/Utils.pm ↑ Summary blib/lib/IPC/PrettyPipe/Execute/IPC/Run.pm »