| 1 | package IPC::PrettyPipe::Cmd; | ||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||
| 3 | # ABSTRACT: A command in an B<IPC::PrettyPipe> pipeline | ||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||
| 5 | 20 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||
| 7 | 20 | ▶ | use List::Util qw[ sum pairs ]; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 8 | 20 | ▶ | use Scalar::Util qw[ blessed ]; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||
| 10 | 20 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||
| 12 | 20 | ▶ | use Safe::Isa; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||
| 14 | 20 | ▶ | use IPC::PrettyPipe::Arg; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 15 | 20 | ▶ | use IPC::PrettyPipe::Stream; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||
| 17 | 20 | ▶ | use Types::Standard -all; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 18 | 20 | ▶ | use Type::Params qw[ validate ]; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||
| 20 | 20 | ▶ | use IPC::PrettyPipe::Types -all; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 21 | 20 | ▶ | use IPC::PrettyPipe::Queue; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 22 | 20 | ▶ | use IPC::PrettyPipe::Arg::Format; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||
| 24 | 20 | ▶ | use String::ShellQuote 'shell_quote'; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||
| 26 | 20 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||
| 28 | 20 | our $VERSION = '0.13'; | |||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||
| 30 | 20 | with 'IPC::PrettyPipe::Queue::Element'; | |||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||
| 32 | 20 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||
| 34 | 20 | ▶ | 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 | |||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||
| 57 | 20 | ▶ | use overload '|' => sub { | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||||||||
| 58 | 3 | my $swap = pop; | |||||||||||||||||||||||||||||||||||
| 59 | 3 | my $pipe = IPC::PrettyPipe->new; | |||||||||||||||||||||||||||||||||||
| 60 | 3 | ▶ | $pipe->add( $_ ) for ( $swap ? reverse( @_ ) : @_ ); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 61 | 3 | $pipe; | |||||||||||||||||||||||||||||||||||
| 62 | 20 | }; | |||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||
| 64 | # need access to has method which will get removed at the end of the | ||||||||||||||||||||||||||||||||||||
| 65 | # compilation of this module | ||||||||||||||||||||||||||||||||||||
| 66 | 20 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 67 | 20 | ▶ | IPC::PrettyPipe::Arg::Format->shadow_attrs( fmt => sub { 'arg' . shift } ); | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||
| 99 | 20 | has cmd => ( | |||||||||||||||||||||||||||||||||||
| 100 | is => 'ro', | ||||||||||||||||||||||||||||||||||||
| 101 | isa => Str, | ||||||||||||||||||||||||||||||||||||
| 102 | required => 1, | ||||||||||||||||||||||||||||||||||||
| 103 | ); | ||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||
| 105 | # delay building args until all attributes have been specified | ||||||||||||||||||||||||||||||||||||
| 106 | 20 | has _init_args => ( | |||||||||||||||||||||||||||||||||||
| 107 | is => 'ro', | ||||||||||||||||||||||||||||||||||||
| 108 | init_arg => 'args', | ||||||||||||||||||||||||||||||||||||
| 109 | coerce => AutoArrayRef->coercion, | ||||||||||||||||||||||||||||||||||||
| 110 | isa => ArrayRef, | ||||||||||||||||||||||||||||||||||||
| 111 | predicate => 1, | ||||||||||||||||||||||||||||||||||||
| 112 | clearer => 1, | ||||||||||||||||||||||||||||||||||||
| 113 | ); | ||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||
| 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 | |||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||
| 152 | has args => ( | ||||||||||||||||||||||||||||||||||||
| 153 | is => 'ro', | ||||||||||||||||||||||||||||||||||||
| 154 | 140 | ▶ | default => sub { IPC::PrettyPipe::Queue->new }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 155 | 20 | init_arg => undef, | |||||||||||||||||||||||||||||||||||
| 156 | ); | ||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||
| 167 | has streams => ( | ||||||||||||||||||||||||||||||||||||
| 168 | is => 'ro', | ||||||||||||||||||||||||||||||||||||
| 169 | 140 | ▶ | default => sub { IPC::PrettyPipe::Queue->new }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 170 | 20 | init_arg => undef, | |||||||||||||||||||||||||||||||||||
| 171 | ); | ||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||
| 210 | has argfmt => ( | ||||||||||||||||||||||||||||||||||||
| 211 | is => 'ro', | ||||||||||||||||||||||||||||||||||||
| 212 | lazy => 1, | ||||||||||||||||||||||||||||||||||||
| 213 | handles => IPC::PrettyPipe::Arg::Format->shadowed_attrs, | ||||||||||||||||||||||||||||||||||||
| 214 | 15 | ▶ | default => sub { IPC::PrettyPipe::Arg::Format->new_from_attrs( shift ) }, | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 215 | 20 | ); | |||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||
| 221 | 141 | ▶ | sub BUILDARGS { | ||||||||||||||||||||||||||||||||||
|
Subroutine
BUILDARGS: called CC=5 SCAR=22.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||
| 223 | 141 | my $class = shift; | |||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||
| 225 | my $args | ||||||||||||||||||||||||||||||||||||
| 226 | = @_ == 1 | ||||||||||||||||||||||||||||||||||||
| 227 | ? ( | ||||||||||||||||||||||||||||||||||||
| 228 | 'HASH' eq ref( $_[0] ) | ||||||||||||||||||||||||||||||||||||
| 229 | ? $_[0] | ||||||||||||||||||||||||||||||||||||
| 230 | : 'ARRAY' eq ref( $_[0] ) | ||||||||||||||||||||||||||||||||||||
| 231 | 0 | ▶ | && @{ $_[0] } == 2 ? { cmd => $_[0][0], args => $_[0][1] } | ||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition0%0/3
"ARRAY" eq ref $_[0] and @{$_[0];} == 2
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
| |||||||||||||||||||||||||||||||||||||
| 232 | : { cmd => $_[0] } ) | ||||||||||||||||||||||||||||||||||||
| 233 | : {@_}; | ||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||
| 235 | ## no critic (ProhibitAccessOfPrivateData) | ||||||||||||||||||||||||||||||||||||
| 236 | 141 | delete @{$args}{ grep { !defined $args->{$_} } keys %$args }; | |||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||
| 238 | 141 | return $args; | |||||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||
| 242 | 140 | ▶ | sub BUILD { | ||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||
| 245 | 140 | my $self = shift; | |||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||
| 247 | 140 | ▶ | if ( $self->_has_init_args ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||
| 249 | 13 | $self->ffadd( @{ $self->_init_args } ); | |||||||||||||||||||||||||||||||||||
| 250 | 13 | $self->_clear_init_args; | |||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||
| 253 | 140 | return; | |||||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||
| 265 | 30 | ▶ | sub quoted_cmd { shell_quote( $_[0]->cmd ) } | ||||||||||||||||||||||||||||||||||
|
Subroutine
quoted_cmd: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||
| 317 | 206 | ▶ | sub add { | ||||||||||||||||||||||||||||||||||
|
Subroutine
add: called CC=12 SCAR=26.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||
| 319 | 206 | my $self = shift; | |||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||
| 321 | 206 | ▶ | unshift @_, 'arg' if @_ == 1; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||
| 323 | ## no critic (ProhibitAccessOfPrivateData) | ||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||
| 325 | 206 | my $argfmt = $self->argfmt->clone; | |||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||
| 327 | 206 | my $argfmt_attrs = IPC::PrettyPipe::Arg::Format->shadowed_attrs; | |||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||
| 329 | my ( $attr ) = validate( | ||||||||||||||||||||||||||||||||||||
| 330 | \@_, | ||||||||||||||||||||||||||||||||||||
| 331 | slurpy Dict [ | ||||||||||||||||||||||||||||||||||||
| 332 | arg => Str | Arg | ArrayRef | HashRef, | ||||||||||||||||||||||||||||||||||||
| 333 | value => Optional [Str], | ||||||||||||||||||||||||||||||||||||
| 334 | argfmt => Optional [ InstanceOf ['IPC::PrettyPipe::Arg::Format'] ], | ||||||||||||||||||||||||||||||||||||
| 335 | 206 | ( map { $_ => Optional [Str] } keys %{$argfmt_attrs} ), | |||||||||||||||||||||||||||||||||||
| 336 | ] ); | ||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||
| 338 | 205 | my $arg = $attr->{arg}; | |||||||||||||||||||||||||||||||||||
| 339 | 205 | my $ref = ref $arg; | |||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||
| 341 | croak( "cannot specify a value if arg is a hash, array, or Arg object\n" ) | ||||||||||||||||||||||||||||||||||||
| 342 | 205 | ▶ | if $ref && exists $attr->{value}; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$ref and exists $attr->{"value"}
MC/DC0%0/2
$ref and exists $attr->{"value"}
$ref
exists $attr->{"value"}
Truth table66%2/3
A and B
A= $refB= exists $attr->{"value"}
| |||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||
| 344 | 205 | ▶ | $argfmt->copy_from( $attr->{argfmt} ) if defined $attr->{argfmt}; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 345 | 205 | $argfmt->copy_from( IPC::PrettyPipe::Arg::Format->new_from_hash( $attr ) ); | |||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||
| 347 | 205 | ▶ | if ( 'HASH' eq $ref ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||
| 349 | 0 | ▶ | while ( my ( $name, $value ) = each %$arg ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||
| 351 | 0 | $self->args->push( | |||||||||||||||||||||||||||||||||||
| 352 | IPC::PrettyPipe::Arg->new( | ||||||||||||||||||||||||||||||||||||
| 353 | name => $name, | ||||||||||||||||||||||||||||||||||||
| 354 | value => $value, | ||||||||||||||||||||||||||||||||||||
| 355 | fmt => $argfmt->clone | ||||||||||||||||||||||||||||||||||||
| 356 | ) ); | ||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||
| 361 | elsif ( 'ARRAY' eq $ref ) { | ||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||
| 363 | 73 | ▶ | croak( "missing value for argument ", $arg->[-1] ) | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 364 | if @$arg % 2; | ||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||
| 366 | 72 | foreach ( pairs @$arg ) { | |||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||
| 368 | 72 | my ( $name, $value ) = @$_; | |||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||
| 370 | 72 | $self->args->push( | |||||||||||||||||||||||||||||||||||
| 371 | IPC::PrettyPipe::Arg->new( | ||||||||||||||||||||||||||||||||||||
| 372 | name => $name, | ||||||||||||||||||||||||||||||||||||
| 373 | value => $value, | ||||||||||||||||||||||||||||||||||||
| 374 | fmt => $argfmt->clone | ||||||||||||||||||||||||||||||||||||
| 375 | ) ); | ||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||
| 377 | } | ||||||||||||||||||||||||||||||||||||
| 378 | } | ||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||
| 380 | elsif ( $arg->$_isa( 'IPC::PrettyPipe::Arg' ) ) { | ||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||
| 382 | 0 | $self->args->push( $arg ); | |||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||
| 386 | # everything else | ||||||||||||||||||||||||||||||||||||
| 387 | else { | ||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||
| 389 | $self->args->push( | ||||||||||||||||||||||||||||||||||||
| 390 | IPC::PrettyPipe::Arg->new( | ||||||||||||||||||||||||||||||||||||
| 391 | name => $attr->{arg}, | ||||||||||||||||||||||||||||||||||||
| 392 | 132 | ▶ | exists $attr->{value} ? ( value => $attr->value ) : (), | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 393 | fmt => $argfmt->clone | ||||||||||||||||||||||||||||||||||||
| 394 | ) ); | ||||||||||||||||||||||||||||||||||||
| 395 | } | ||||||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||||||
| 397 | 204 | return; | |||||||||||||||||||||||||||||||||||
| 398 | } | ||||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||||||||||
| 449 | 137 | ▶ | sub ffadd { | ||||||||||||||||||||||||||||||||||
|
Subroutine
ffadd: called CC=6 SCAR=18.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||||||||||
| 451 | 137 | my $self = shift; | |||||||||||||||||||||||||||||||||||
| 452 | 137 | my @args = @_; | |||||||||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||||||||||
| 454 | 137 | my $argfmt = $self->argfmt->clone; | |||||||||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||||||||||
| 456 | 137 | ▶ | for ( my $idx = 0 ; $idx < @args ; $idx++ ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||||||||
| 458 | 271 | my $t = $args[$idx]; | |||||||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||||||
| 460 | 271 | ▶ | if ( $t->$_isa( 'IPC::PrettyPipe::Arg::Format' ) ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||||||||||
| 462 | 13 | $t->copy_into( $argfmt ); | |||||||||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||||||||||
| 464 | } | ||||||||||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||||||||||
| 466 | elsif ( $t->$_isa( 'IPC::PrettyPipe::Arg' ) ) { | ||||||||||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||||||||||
| 468 | 0 | $self->add( arg => $t ); | |||||||||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||||||||||
| 471 | } | ||||||||||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||||||||
| 473 | elsif ( ref( $t ) =~ /^(ARRAY|HASH)$/ ) { | ||||||||||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||||||||||
| 475 | 72 | $self->add( arg => $t, argfmt => $argfmt->clone ); | |||||||||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||||||||||
| 477 | } | ||||||||||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||||||||||
| 479 | elsif ( $t->$_isa( 'IPC::PrettyPipe::Stream' ) ) { | ||||||||||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||||||||||
| 481 | 0 | $self->stream( $t ); | |||||||||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||||||||||
| 483 | } | ||||||||||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||||||||||
| 485 | else { | ||||||||||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||||||||||
| 487 | 186 | ▶ | try { | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||||||||
| 489 | 186 | my $stream = IPC::PrettyPipe::Stream->new( | |||||||||||||||||||||||||||||||||||
| 490 | spec => $t, | ||||||||||||||||||||||||||||||||||||
| 491 | strict => 0, | ||||||||||||||||||||||||||||||||||||
| 492 | ); | ||||||||||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||||||||||
| 494 | 54 | ▶ | if ( $stream->requires_file ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||||||||||
| 496 | 52 | ▶ | croak( "arg[$idx]: stream operator $t requires a file\n" ) | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 497 | if ++$idx == @args; | ||||||||||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||||||||||
| 499 | 52 | $stream->file( $args[$idx] ); | |||||||||||||||||||||||||||||||||||
| 500 | } | ||||||||||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||||||||||
| 502 | 54 | $self->stream( $stream ); | |||||||||||||||||||||||||||||||||||
| 503 | } | ||||||||||||||||||||||||||||||||||||
| 504 | 132 | ▶ | catch { | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||||||||||
| 506 | 132 | ▶ | die $_ if /requires a file/; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||||||||||
| 508 | 132 | $self->add( arg => $t, argfmt => $argfmt->clone ); | |||||||||||||||||||||||||||||||||||
| 509 | 186 | }; | |||||||||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||||||||||
| 511 | } | ||||||||||||||||||||||||||||||||||||
| 512 | } | ||||||||||||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||||||||||
| 514 | 137 | return; | |||||||||||||||||||||||||||||||||||
| 515 | } | ||||||||||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||||||||||
| 519 | |||||||||||||||||||||||||||||||||||||
| 520 | |||||||||||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||||||||||
| 522 | |||||||||||||||||||||||||||||||||||||
| 523 | |||||||||||||||||||||||||||||||||||||
| 524 | |||||||||||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||||||||||
| 529 | |||||||||||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||||||||||
| 531 | 54 | ▶ | sub stream { | ||||||||||||||||||||||||||||||||||
|
Subroutine
stream: called CC=5 SCAR=20.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||||||||||
| 533 | 54 | my $self = shift; | |||||||||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||||||||||
| 535 | 54 | my $spec = shift; | |||||||||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||||||||||
| 537 | 54 | ▶ | if ( $spec->$_isa( 'IPC::PrettyPipe::Stream' ) ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||||||||||
| 539 | 54 | ▶ | croak( "too many arguments\n" ) | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 540 | if @_; | ||||||||||||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||||||||||
| 542 | 54 | $self->streams->push( $spec ); | |||||||||||||||||||||||||||||||||||
| 543 | |||||||||||||||||||||||||||||||||||||
| 544 | } | ||||||||||||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||||||||||
| 546 | elsif ( !ref $spec ) { | ||||||||||||||||||||||||||||||||||||
| 547 | |||||||||||||||||||||||||||||||||||||
| 548 | 0 | ▶ | $self->streams->push( | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 549 | IPC::PrettyPipe::Stream->new( | ||||||||||||||||||||||||||||||||||||
| 550 | spec => $spec, | ||||||||||||||||||||||||||||||||||||
| 551 | +@_ ? ( file => @_ ) : () ) ); | ||||||||||||||||||||||||||||||||||||
| 552 | } | ||||||||||||||||||||||||||||||||||||
| 553 | |||||||||||||||||||||||||||||||||||||
| 554 | else { | ||||||||||||||||||||||||||||||||||||
| 555 | |||||||||||||||||||||||||||||||||||||
| 556 | 0 | croak( "illegal stream specification\n" ); | |||||||||||||||||||||||||||||||||||
| 557 | |||||||||||||||||||||||||||||||||||||
| 558 | } | ||||||||||||||||||||||||||||||||||||
| 559 | |||||||||||||||||||||||||||||||||||||
| 560 | |||||||||||||||||||||||||||||||||||||
| 561 | 54 | return; | |||||||||||||||||||||||||||||||||||
| 562 | } | ||||||||||||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||||||||||
| 564 | |||||||||||||||||||||||||||||||||||||
| 565 | |||||||||||||||||||||||||||||||||||||
| 566 | |||||||||||||||||||||||||||||||||||||
| 567 | |||||||||||||||||||||||||||||||||||||
| 568 | |||||||||||||||||||||||||||||||||||||
| 569 | |||||||||||||||||||||||||||||||||||||
| 570 | |||||||||||||||||||||||||||||||||||||
| 571 | |||||||||||||||||||||||||||||||||||||
| 572 | |||||||||||||||||||||||||||||||||||||
| 573 | |||||||||||||||||||||||||||||||||||||
| 574 | 61 | ▶ | sub valmatch { | ||||||||||||||||||||||||||||||||||
|
Subroutine
valmatch: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 575 | 61 | my $self = shift; | |||||||||||||||||||||||||||||||||||
| 576 | 61 | my $pattern = shift; | |||||||||||||||||||||||||||||||||||
| 577 | |||||||||||||||||||||||||||||||||||||
| 578 | # find number of matches; | ||||||||||||||||||||||||||||||||||||
| 579 | 61 | return sum 0, map { $_->valmatch( $pattern ) } @{ $self->args->elements }; | |||||||||||||||||||||||||||||||||||
| 580 | } | ||||||||||||||||||||||||||||||||||||
| 581 | |||||||||||||||||||||||||||||||||||||
| 582 | |||||||||||||||||||||||||||||||||||||
| 583 | |||||||||||||||||||||||||||||||||||||
| 584 | |||||||||||||||||||||||||||||||||||||
| 585 | |||||||||||||||||||||||||||||||||||||
| 586 | |||||||||||||||||||||||||||||||||||||
| 587 | |||||||||||||||||||||||||||||||||||||
| 588 | |||||||||||||||||||||||||||||||||||||
| 589 | |||||||||||||||||||||||||||||||||||||
| 590 | |||||||||||||||||||||||||||||||||||||
| 591 | |||||||||||||||||||||||||||||||||||||
| 592 | |||||||||||||||||||||||||||||||||||||
| 593 | |||||||||||||||||||||||||||||||||||||
| 594 | |||||||||||||||||||||||||||||||||||||
| 595 | |||||||||||||||||||||||||||||||||||||
| 596 | |||||||||||||||||||||||||||||||||||||
| 597 | |||||||||||||||||||||||||||||||||||||
| 598 | |||||||||||||||||||||||||||||||||||||
| 599 | |||||||||||||||||||||||||||||||||||||
| 600 | |||||||||||||||||||||||||||||||||||||
| 601 | |||||||||||||||||||||||||||||||||||||
| 602 | |||||||||||||||||||||||||||||||||||||
| 603 | |||||||||||||||||||||||||||||||||||||
| 604 | |||||||||||||||||||||||||||||||||||||
| 605 | |||||||||||||||||||||||||||||||||||||
| 606 | |||||||||||||||||||||||||||||||||||||
| 607 | |||||||||||||||||||||||||||||||||||||
| 608 | 31 | ▶ | sub valsubst { | ||||||||||||||||||||||||||||||||||
|
Subroutine
valsubst: called CC=12 SCAR=25.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 609 | 31 | my $self = shift; | |||||||||||||||||||||||||||||||||||
| 610 | |||||||||||||||||||||||||||||||||||||
| 611 | 31 | ▶ | my @args = ( shift, shift, @_ > 1 ? {@_} : @_ ); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 612 | |||||||||||||||||||||||||||||||||||||
| 613 | |||||||||||||||||||||||||||||||||||||
| 614 | ## no critic (ProhibitAccessOfPrivateData) | ||||||||||||||||||||||||||||||||||||
| 615 | |||||||||||||||||||||||||||||||||||||
| 616 | 31 | my ( $pattern, $value, $args ) = validate( | |||||||||||||||||||||||||||||||||||
| 617 | \@args, | ||||||||||||||||||||||||||||||||||||
| 618 | RegexpRef, | ||||||||||||||||||||||||||||||||||||
| 619 | Str, | ||||||||||||||||||||||||||||||||||||
| 620 | Optional [ | ||||||||||||||||||||||||||||||||||||
| 621 | Dict [ | ||||||||||||||||||||||||||||||||||||
| 622 | lastvalue => Optional [Str], | ||||||||||||||||||||||||||||||||||||
| 623 | firstvalue => Optional [Str] ] | ||||||||||||||||||||||||||||||||||||
| 624 | ], | ||||||||||||||||||||||||||||||||||||
| 625 | ); | ||||||||||||||||||||||||||||||||||||
| 626 | |||||||||||||||||||||||||||||||||||||
| 627 | 31 | my $nmatch = $self->valmatch( $pattern ); | |||||||||||||||||||||||||||||||||||
| 628 | |||||||||||||||||||||||||||||||||||||
| 629 | 31 | ▶ | if ( $nmatch == 1 ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 630 | |||||||||||||||||||||||||||||||||||||
| 631 | 18 | ▶ | $args->{lastvalue} //= $args->{firstvalue} // $value; | ||||||||||||||||||||||||||||||||||
|
Condition66%4/6
$args->{"lastvalue"} //= $args->{"firstvalue"} // $value
$args->{"firstvalue"} // $value
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
| |||||||||||||||||||||||||||||||||||||
| 632 | 18 | ▶ | $args->{firstvalue} //= $args->{lastvalue}; | ||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$args->{"firstvalue"} //= $args->{"lastvalue"}
MC/DC0%0/2
$args->{"firstvalue"} //= $args->{"lastvalue"}
$args->{"firstvalue"}
$args->{"lastvalue"}
Truth table66%2/3
A //= B
A= $args->{"firstvalue"}B= $args->{"lastvalue"}
| |||||||||||||||||||||||||||||||||||||
| 633 | |||||||||||||||||||||||||||||||||||||
| 634 | } | ||||||||||||||||||||||||||||||||||||
| 635 | else { | ||||||||||||||||||||||||||||||||||||
| 636 | 13 | ▶ | $args->{lastvalue} ||= $value; | ||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$args->{"lastvalue"} ||= $value
MC/DC0%0/2
$args->{"lastvalue"} ||= $value
$args->{"lastvalue"}
$value
Truth table66%2/3
A ||= B
A= $args->{"lastvalue"}B= $value
| |||||||||||||||||||||||||||||||||||||
| 637 | 13 | ▶ | $args->{firstvalue} ||= $value; | ||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$args->{"firstvalue"} ||= $value
MC/DC0%0/2
$args->{"firstvalue"} ||= $value
$args->{"firstvalue"}
$value
Truth table66%2/3
A ||= B
A= $args->{"firstvalue"}B= $value
| |||||||||||||||||||||||||||||||||||||
| 638 | } | ||||||||||||||||||||||||||||||||||||
| 639 | |||||||||||||||||||||||||||||||||||||
| 640 | 31 | my $match = 0; | |||||||||||||||||||||||||||||||||||
| 641 | 31 | foreach ( @{ $self->args->elements } ) { | |||||||||||||||||||||||||||||||||||
| 642 | |||||||||||||||||||||||||||||||||||||
| 643 | $match++ | ||||||||||||||||||||||||||||||||||||
| 644 | if $_->valsubst( $pattern, | ||||||||||||||||||||||||||||||||||||
| 645 | $match == 0 ? $args->{firstvalue} | ||||||||||||||||||||||||||||||||||||
| 646 | : $match == ( $nmatch - 1 ) ? $args->{lastvalue} | ||||||||||||||||||||||||||||||||||||
| 647 | 55 | ▶ | : $value ); | ||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||
| 648 | } | ||||||||||||||||||||||||||||||||||||
| 649 | |||||||||||||||||||||||||||||||||||||
| 650 | 31 | return $match; | |||||||||||||||||||||||||||||||||||
| 651 | } | ||||||||||||||||||||||||||||||||||||
| 652 | |||||||||||||||||||||||||||||||||||||
| 653 | |||||||||||||||||||||||||||||||||||||
| 654 | 20 | 1; | |||||||||||||||||||||||||||||||||||
| 655 | |||||||||||||||||||||||||||||||||||||
| 656 | # | ||||||||||||||||||||||||||||||||||||
| 657 | # This file is part of IPC-PrettyPipe | ||||||||||||||||||||||||||||||||||||
| 658 | # | ||||||||||||||||||||||||||||||||||||
| 659 | # This software is Copyright (c) 2018 by Smithsonian Astrophysical Observatory. | ||||||||||||||||||||||||||||||||||||
| 660 | # | ||||||||||||||||||||||||||||||||||||
| 661 | # This is free software, licensed under: | ||||||||||||||||||||||||||||||||||||
| 662 | # | ||||||||||||||||||||||||||||||||||||
| 663 | # The GNU General Public License, Version 3, June 2007 | ||||||||||||||||||||||||||||||||||||
| 664 | # | ||||||||||||||||||||||||||||||||||||
| 665 | |||||||||||||||||||||||||||||||||||||
| 666 | __END__ | ||||||||||||||||||||||||||||||||||||