| 1 | package Iterator::Flex::Zip; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | # ABSTRACT: Zip Iterator Class | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use v5.28; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use experimental 'signatures', 'declared_refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 3 | our $VERSION = '0.33'; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 3 | ▶ | use Iterator::Flex::Factory 'to_iterator'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 3 | ▶ | use Iterator::Flex::Utils qw[ THROW STATE EXHAUSTION :IterAttrs :IterStates throw_failure ]; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 3 | ▶ | use Ref::Util 'is_ref', 'is_hashref', 'is_blessed_ref'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 3 | ▶ | use List::Util 'first'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 3 | ▶ | use parent 'Iterator::Flex::Base'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 3 | ▶ | use constant { map { $_ => lc } qw( ON_EXHAUSTION TRUNCATE THROW INSERT ) }; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 3 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 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 | ▶ | sub new ( $class, @args ) { | |||||||||||||||||||||||||||
|
Subroutine
new: called CC=12 SCAR=25.1
Pod
documented
| |||||||||||||||||||||||||||||
| 95 | 13 | ▶ | my $pars = is_hashref( $args[-1] ) ? pop @args : {}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 13 | ▶ | throw_failure( parameter => 'not enough parameters' ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | unless @args; | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 13 | my @iterators; | |||||||||||||||||||||||||||
| 101 | my @keys; | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | # distinguish between ( key => iterator, key =>iterator ) and ( iterator, iterator ); | ||||||||||||||||||||||||||||
| 104 | 13 | ▶ | if ( is_ref( $args[0] ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 105 | 8 | @iterators = @args; | |||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | else { | ||||||||||||||||||||||||||||
| 108 | 5 | ▶ | throw_failure( parameter => 'expected an even number of arguments' ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 109 | if @args % 2; | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 5 | ▶ | while ( @args ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 112 | 15 | push @keys, shift @args; | |||||||||||||||||||||||||||
| 113 | 15 | push @iterators, shift @args; | |||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | ## no critic (AmbiguousNames) | ||||||||||||||||||||||||||||
| 118 | 13 | my ( @set, @insert ); | |||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 13 | my %attr = ( | |||||||||||||||||||||||||||
| 121 | keys => \@keys, | ||||||||||||||||||||||||||||
| 122 | depends => \@iterators, | ||||||||||||||||||||||||||||
| 123 | set => \@set, | ||||||||||||||||||||||||||||
| 124 | insert => \@insert, | ||||||||||||||||||||||||||||
| 125 | value => [], | ||||||||||||||||||||||||||||
| 126 | ); | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 13 | ▶ | if ( defined( my $on_exhaustion = delete $pars->{ +ON_EXHAUSTION } ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | 8 | ▶ | if ( is_hashref( $on_exhaustion ) ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 131 | 6 | my @ekeys = keys $on_exhaustion->%*; | |||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | 6 | my %idx; | |||||||||||||||||||||||||||
| 134 | 6 | @idx{ 0 .. $#iterators } = 0 .. $#iterators; | |||||||||||||||||||||||||||
| 135 | 6 | ▶ | @idx{@keys} = 0 .. $#iterators | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 136 | if @keys; | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | 6 | my @iset = @idx{@ekeys}; | |||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | throw_failure( parameter => ON_EXHAUSTION . ' illegal iterator label or index' ) | ||||||||||||||||||||||||||||
| 141 | 6 | ▶ | if defined first { !defined } @iset; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | 6 | @set[@iset] = ( !!1 ) x @iset; | |||||||||||||||||||||||||||
| 144 | 6 | @insert[@iset] = $on_exhaustion->@{@ekeys}; | |||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | 6 | $attr{set} = \@set; | |||||||||||||||||||||||||||
| 147 | 6 | $attr{insert} = \@insert; | |||||||||||||||||||||||||||
| 148 | 6 | $attr{ +ON_EXHAUSTION } = INSERT; | |||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||
| 150 | 4 | ▶ | elsif ( is_ref( $on_exhaustion ) or !first { $on_exhaustion eq $_ } TRUNCATE, THROW ) { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=1.2
Condition33%1/3
Ref::Util::XS::is_ref($on_exhaustion) or not &first(sub {
$on_exhaustion eq $_;
}
, "truncate", "throw")
MC/DC0%0/2
Ref::Util::XS::is_ref($on_exhaustion) or not &first(sub {
$on_exhaustion eq $_;
}
, "truncate", "throw")
Ref::Util::XS::is_ref($on_exhaustion)
not &first(sub {
$on_exhaustion eq $_;
}
, "truncate", "throw")
Truth table33%1/3
A or not(B)
A= Ref::Util::XS::is_ref($on_exhaustion)B= not &first(sub {
$on_exhaustion eq $_;
}
, "truncate", "throw")
| |||||||||||||||||||||||||||||
| 151 | 0 | throw_failure( parameter => ON_EXHAUSTION . ": unexpected value: $on_exhaustion" ); | |||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||
| 153 | else { | ||||||||||||||||||||||||||||
| 154 | 2 | $attr{ +ON_EXHAUSTION } = $on_exhaustion; | |||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||
| 157 | else { | ||||||||||||||||||||||||||||
| 158 | 5 | $attr{ +ON_EXHAUSTION } = TRUNCATE; | |||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | 13 | $class->SUPER::new( \%attr, $pars ); | |||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | ## no critic (ExcessComplexity) | ||||||||||||||||||||||||||||
| 166 | ▶ | sub construct ( $class, $state ) { | |||||||||||||||||||||||||||
|
Subroutine
construct: called CC=9 SCAR=22.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 167 | 13 | ▶ | throw_failure( parameter => q{state must be a HASH reference} ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 168 | unless is_hashref( $state ); | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | 13 | ▶ | $state->{value} //= []; | ||||||||||||||||||||||||||
|
Condition50%1/2
$state->{"value"} //= []
MC/DC0%0/1
$state->{"value"} //= []
$state->{"value"}
Truth table50%1/2
A
A= $state->{"value"}
| |||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | ## no critic (AmbiguousNames) | ||||||||||||||||||||||||||||
| 173 | my ( \@depends, \@keys, \@value, \@insert, \@set, $on_exhaustion, $thaw ) | ||||||||||||||||||||||||||||
| 174 | 13 | = @{$state}{qw[ depends keys value insert set on_exhaustion thaw ]}; | |||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | # transform into iterators if required. | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | my @iterators | ||||||||||||||||||||||||||||
| 179 | 13 | = map { to_iterator( $_, { ( +EXHAUSTION ) => THROW } ) } @depends; | |||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | 13 | ▶ | throw_failure( parameter => q{number of keys not equal to number of iterators} ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@keys and @keys != @iterators
MC/DC0%0/2
@keys and @keys != @iterators
@keys
@keys != @iterators
Truth table66%2/3
A and B
A= @keysB= @keys != @iterators
| |||||||||||||||||||||||||||||
| 182 | if @keys && @keys != @iterators; | ||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | 13 | ▶ | @value = map { $_->current } @iterators | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 185 | if $thaw; | ||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | 13 | my $self; | |||||||||||||||||||||||||||
| 188 | my $iterator_state; | ||||||||||||||||||||||||||||
| 189 | my %params = ( | ||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | ( +_NAME ) => 'izip', | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | ( +_SELF ) => \$self, | ||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | ( +STATE ) => \$iterator_state, | ||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | ( +CURRENT ) => sub { | ||||||||||||||||||||||||||||
| 199 | 2 | ▶ | return undef if !@value; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=15.9
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 200 | 1 | ▶ | return $self->signal_exhaustion if $iterator_state eq IterState_EXHAUSTED; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 201 | 1 | ▶ | if ( @keys ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 202 | 0 | my %value; | |||||||||||||||||||||||||||
| 203 | 0 | @value{@keys} = @value; | |||||||||||||||||||||||||||
| 204 | 0 | return \%value; | |||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||
| 206 | else { | ||||||||||||||||||||||||||||
| 207 | 1 | return [@value]; | |||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||
| 209 | }, | ||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | 3 | ▶ | ( +RESET ) => sub { @value = () }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 212 | ▶ | ( +REWIND ) => sub { }, | |||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 213 | 13 | ( +_DEPENDS ) => \@iterators, | |||||||||||||||||||||||||||
| 214 | ); | ||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||
| 216 | 13 | ▶ | if ( $on_exhaustion eq TRUNCATE ) { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | $params{ +NEXT } = sub { | ||||||||||||||||||||||||||||
| 219 | 26 | ▶ | return $self->signal_exhaustion if $iterator_state == IterState_EXHAUSTED; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=18.2
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||
| 221 | 26 | my @nvalue; | |||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | eval { | ||||||||||||||||||||||||||||
| 224 | 26 | @nvalue = map { $_->() } @iterators; | |||||||||||||||||||||||||||
| 225 | 21 | 1; | |||||||||||||||||||||||||||
| 226 | 26 | ▶ | } or do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 227 | 5 | ▶ | die $@ | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
Ref::Util::XS::is_blessed_ref($@) and $@->isa("Iterator::Flex::Failure::Exhausted")
MC/DC0%0/2
Ref::Util::XS::is_blessed_ref($@) and $@->isa("Iterator::Flex::Failure::Exhausted")
Ref::Util::XS::is_blessed_ref($@)
$@->isa("Iterator::Flex::Failure::Exhausted")
Truth table33%1/3
A and B
A= Ref::Util::XS::is_blessed_ref($@)B= $@->isa("Iterator::Flex::Failure::Exhausted")
| |||||||||||||||||||||||||||||
| 228 | unless is_blessed_ref( $@ ) | ||||||||||||||||||||||||||||
| 229 | && $@->isa( 'Iterator::Flex::Failure::Exhausted' ); | ||||||||||||||||||||||||||||
| 230 | 5 | return $self->signal_exhaustion; | |||||||||||||||||||||||||||
| 231 | }; | ||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||
| 233 | 21 | @value = @nvalue; | |||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||
| 235 | 21 | ▶ | if ( @keys ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 236 | 6 | my %value; | |||||||||||||||||||||||||||
| 237 | 6 | @value{@keys} = @value; | |||||||||||||||||||||||||||
| 238 | 6 | return \%value; | |||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||
| 240 | else { | ||||||||||||||||||||||||||||
| 241 | 15 | return [@value]; | |||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||
| 243 | 5 | }; | |||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||
| 246 | elsif ( $on_exhaustion eq THROW ) { | ||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||
| 248 | $params{ +NEXT } = sub { | ||||||||||||||||||||||||||||
| 249 | 8 | ▶ | return $self->signal_exhaustion if $iterator_state == IterState_EXHAUSTED; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=12 SCAR=25.4
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||
| 251 | 8 | my @nvalue; | |||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||
| 253 | 8 | my $idx = -1; | |||||||||||||||||||||||||||
| 254 | eval { | ||||||||||||||||||||||||||||
| 255 | ## no critic (ComplexMappings) | ||||||||||||||||||||||||||||
| 256 | 8 | @nvalue = map { $idx++; $_->() } @iterators; | |||||||||||||||||||||||||||
| 257 | 6 | 1; | |||||||||||||||||||||||||||
| 258 | 8 | ▶ | } or do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 259 | 2 | ▶ | die $@ | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
Ref::Util::XS::is_blessed_ref($@) and $@->isa("Iterator::Flex::Failure::Exhausted")
MC/DC0%0/2
Ref::Util::XS::is_blessed_ref($@) and $@->isa("Iterator::Flex::Failure::Exhausted")
Ref::Util::XS::is_blessed_ref($@)
$@->isa("Iterator::Flex::Failure::Exhausted")
Truth table33%1/3
A and B
A= Ref::Util::XS::is_blessed_ref($@)B= $@->isa("Iterator::Flex::Failure::Exhausted")
| |||||||||||||||||||||||||||||
| 260 | unless is_blessed_ref( $@ ) | ||||||||||||||||||||||||||||
| 261 | && $@->isa( 'Iterator::Flex::Failure::Exhausted' ); | ||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||
| 263 | # if all of the iterators have been exhausted, | ||||||||||||||||||||||||||||
| 264 | # then we're ok. Otherwise, find out which ones | ||||||||||||||||||||||||||||
| 265 | # are | ||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||
| 267 | 2 | my @exhausted = ( $idx ); | |||||||||||||||||||||||||||
| 268 | 2 | ▶ | while ( ++$idx < @iterators ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 269 | 4 | ▶ | if ( !eval { $iterators[$idx]->(); 1 } ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 270 | 2 | ▶ | die $@ | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
Ref::Util::XS::is_blessed_ref($@) and $@->isa("Iterator::Flex::Failure::Exhausted")
MC/DC0%0/2
Ref::Util::XS::is_blessed_ref($@) and $@->isa("Iterator::Flex::Failure::Exhausted")
Ref::Util::XS::is_blessed_ref($@)
$@->isa("Iterator::Flex::Failure::Exhausted")
Truth table33%1/3
A and B
A= Ref::Util::XS::is_blessed_ref($@)B= $@->isa("Iterator::Flex::Failure::Exhausted")
| |||||||||||||||||||||||||||||
| 271 | unless is_blessed_ref( $@ ) | ||||||||||||||||||||||||||||
| 272 | && $@->isa( 'Iterator::Flex::Failure::Exhausted' ); | ||||||||||||||||||||||||||||
| 273 | 2 | push @exhausted, $idx; | |||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||
| 276 | 2 | ▶ | return $self->signal_exhaustion | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 277 | if @exhausted == @iterators; | ||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||
| 279 | 2 | ▶ | @exhausted = @keys[@exhausted] | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 280 | if @keys; | ||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||
| 282 | 2 | throw_failure( Truncated => \@exhausted ); | |||||||||||||||||||||||||||
| 283 | }; | ||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||
| 285 | 6 | @value = @nvalue; | |||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||
| 287 | 6 | ▶ | if ( @keys ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 288 | 3 | my %value; | |||||||||||||||||||||||||||
| 289 | 3 | @value{@keys} = @value; | |||||||||||||||||||||||||||
| 290 | 3 | return \%value; | |||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||
| 292 | else { | ||||||||||||||||||||||||||||
| 293 | 3 | return [@value]; | |||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||
| 295 | 2 | }; | |||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||
| 298 | elsif ( $on_exhaustion eq INSERT ) { | ||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||
| 300 | 6 | my @exhausted = ( !!0 ) x @iterators; | |||||||||||||||||||||||||||
| 301 | 6 | my $nexhausted = 0; | |||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||
| 303 | $params{ +NEXT } = sub { | ||||||||||||||||||||||||||||
| 304 | 28 | ▶ | return $self->signal_exhaustion | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=10 SCAR=23.4
Branch: 1 branch
Condition33%1/3
$iterator_state == 1 or $nexhausted == @iterators
MC/DC0%0/2
$iterator_state == 1 or $nexhausted == @iterators
$iterator_state == 1
$nexhausted == @iterators
Truth table33%1/3
A or B
A= $iterator_state == 1B= $nexhausted == @iterators
| |||||||||||||||||||||||||||||
| 305 | if $iterator_state == IterState_EXHAUSTED | ||||||||||||||||||||||||||||
| 306 | || $nexhausted == @iterators; | ||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||
| 308 | 28 | my @nvalue; | |||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||
| 310 | 28 | for my $idx ( 0 .. $#iterators ) { | |||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||
| 312 | 80 | my $value; | |||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||
| 314 | 80 | ▶ | if ( $exhausted[$idx] ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 315 | 4 | $value = $insert[$idx]; | |||||||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||||||||
| 317 | else { | ||||||||||||||||||||||||||||
| 318 | 76 | ▶ | eval { $value = $iterators[$idx]->(); 1 } or do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 319 | 14 | ▶ | die $@ | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
Ref::Util::XS::is_blessed_ref($@) and $@->isa("Iterator::Flex::Failure::Exhausted")
MC/DC0%0/2
Ref::Util::XS::is_blessed_ref($@) and $@->isa("Iterator::Flex::Failure::Exhausted")
Ref::Util::XS::is_blessed_ref($@)
$@->isa("Iterator::Flex::Failure::Exhausted")
Truth table33%1/3
A and B
A= Ref::Util::XS::is_blessed_ref($@)B= $@->isa("Iterator::Flex::Failure::Exhausted")
| |||||||||||||||||||||||||||||
| 320 | unless is_blessed_ref( $@ ) | ||||||||||||||||||||||||||||
| 321 | && $@->isa( 'Iterator::Flex::Failure::Exhausted' ); | ||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||
| 323 | # if insert value not provided for this iterator, | ||||||||||||||||||||||||||||
| 324 | # abort | ||||||||||||||||||||||||||||
| 325 | 14 | ▶ | return $self->signal_exhaustion if !$set[$idx]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||
| 327 | 8 | $nexhausted++; | |||||||||||||||||||||||||||
| 328 | 8 | $exhausted[$idx] = !!1; | |||||||||||||||||||||||||||
| 329 | 8 | $value = $insert[$idx]; | |||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||
| 333 | 74 | push @nvalue, $value; | |||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||
| 336 | 22 | @value = @nvalue; | |||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||
| 338 | 22 | ▶ | if ( @keys ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 339 | 11 | my %value; | |||||||||||||||||||||||||||
| 340 | 11 | @value{@keys} = @value; | |||||||||||||||||||||||||||
| 341 | 11 | return \%value; | |||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||
| 343 | else { | ||||||||||||||||||||||||||||
| 344 | 11 | return [@value]; | |||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||
| 346 | 6 | }; | |||||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||
| 350 | 13 | return \%params; | |||||||||||||||||||||||||||
| 351 | } | ||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||
| 353 | 3 | __PACKAGE__->_add_roles( qw[ | |||||||||||||||||||||||||||
| 354 | State::Closure | ||||||||||||||||||||||||||||
| 355 | Next::ClosedSelf | ||||||||||||||||||||||||||||
| 356 | Current::Closure | ||||||||||||||||||||||||||||
| 357 | Reset::Closure | ||||||||||||||||||||||||||||
| 358 | Rewind::Closure | ||||||||||||||||||||||||||||
| 359 | ] ); | ||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||
| 361 | 3 | 1; | |||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||
| 363 | # | ||||||||||||||||||||||||||||
| 364 | # This file is part of Iterator-Flex | ||||||||||||||||||||||||||||
| 365 | # | ||||||||||||||||||||||||||||
| 366 | # This software is Copyright (c) 2018 by Smithsonian Astrophysical Observatory. | ||||||||||||||||||||||||||||
| 367 | # | ||||||||||||||||||||||||||||
| 368 | # This is free software, licensed under: | ||||||||||||||||||||||||||||
| 369 | # | ||||||||||||||||||||||||||||
| 370 | # The GNU General Public License, Version 3, June 2007 | ||||||||||||||||||||||||||||
| 371 | # | ||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||
| 373 | __END__ | ||||||||||||||||||||||||||||