| 1 | package Iterator::Flex::Chunk; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | # ABSTRACT: Chunk 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'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 3 | our $VERSION = '0.34'; | |||||||||||||||||||||||||||||||||||||||||
| 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; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 3 | ▶ | use parent 'Iterator::Flex::Base'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 3 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 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 | 7 | ▶ | sub new ( $class, $iterable, $pars = {} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | 7 | my %pars = $pars->%*; | |||||||||||||||||||||||||||||||||||||||||
| 57 | 7 | ▶ | my $capacity = delete $pars{capacity} // 1; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
delete $pars{"capacity"} // 1
MC/DC0%0/1
delete $pars{"capacity"} // 1
delete $pars{"capacity"}
Truth table50%1/2
A
A= delete $pars{"capacity"}
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | 7 | ▶ | Scalar::Util::looks_like_number( $capacity ) && int( $capacity ) == $capacity && $capacity > 0 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
&Scalar::Util::looks_like_number($capacity) and int $capacity == $capacity and $capacity > 0
&Scalar::Util::looks_like_number($capacity) and int $capacity == $capacity
MC/DC100%3/3
&Scalar::Util::looks_like_number($capacity) and int $capacity == $capacity and $capacity > 0
&Scalar::Util::looks_like_number($capacity)
int $capacity == $capacity
$capacity > 0
Truth table100%4/4
A and B and C
A= &Scalar::Util::looks_like_number($capacity)B= int $capacity == $capacityC= $capacity > 0
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | or throw_failure( parameter => "parameter 'capacity' ($capacity) is not a positive integer" ); | ||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | 3 | $class->SUPER::new( { | |||||||||||||||||||||||||||||||||||||||||
| 62 | capacity => $capacity, | ||||||||||||||||||||||||||||||||||||||||||
| 63 | src => $iterable, | ||||||||||||||||||||||||||||||||||||||||||
| 64 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 65 | \%pars, | ||||||||||||||||||||||||||||||||||||||||||
| 66 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 3 | ▶ | sub construct ( $class, $state ) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
construct: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | 3 | ▶ | throw_failure( parameter => q{'state' parameter must be a HASH reference} ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | unless Ref::Util::is_hashref( $state ); | ||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | 3 | my ( $src, $capacity ) = @{$state}{qw[ src capacity ]}; | |||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | 3 | $src | |||||||||||||||||||||||||||||||||||||||||
| 77 | = to_iterator( $src, { ( +EXHAUSTION ) => THROW } ); | ||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | 3 | my $self; | |||||||||||||||||||||||||||||||||||||||||
| 80 | my $iterator_state; | ||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | # This iterator may have to delay signalling exhaustion for one | ||||||||||||||||||||||||||||||||||||||||||
| 83 | # cycle if the input iterator is exhausted and the current chunk | ||||||||||||||||||||||||||||||||||||||||||
| 84 | # is not empty | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 3 | my $next_is_exhausted = !!0; | |||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | return { | ||||||||||||||||||||||||||||||||||||||||||
| 88 | ( +_NAME ) => 'ichunk', | ||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | ( +_SELF ) => \$self, | ||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | ( +STATE ) => \$iterator_state, | ||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | 16 | ▶ | ( +NEXT ) => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=8 SCAR=21.1
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | 16 | ▶ | return $self->signal_exhaustion | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$iterator_state == 1 or $next_is_exhausted
MC/DC50%1/2
$iterator_state == 1 or $next_is_exhausted
$iterator_state == 1
$next_is_exhausted
Truth table66%2/3
A or B
A= $iterator_state == 1B= $next_is_exhausted
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | if $iterator_state == IterState_EXHAUSTED || $next_is_exhausted; | ||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | 14 | my @chunked; | |||||||||||||||||||||||||||||||||||||||||
| 99 | eval { | ||||||||||||||||||||||||||||||||||||||||||
| 100 | 14 | ▶ | push @chunked, $src->() while @chunked < $capacity; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | 10 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 102 | 14 | ▶ | } or do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | 4 | ▶ | 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")
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | unless Ref::Util::is_blessed_ref( $@ ) | ||||||||||||||||||||||||||||||||||||||||||
| 105 | && $@->isa( 'Iterator::Flex::Failure::Exhausted' ); | ||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | 4 | ▶ | return $self->signal_exhaustion if !@chunked; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | 2 | $next_is_exhausted = !!1; | |||||||||||||||||||||||||||||||||||||||||
| 109 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 110 | 12 | return \@chunked; | |||||||||||||||||||||||||||||||||||||||||
| 111 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 112 | 4 | ▶ | ( +RESET ) => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | 4 | $next_is_exhausted = !!0; | |||||||||||||||||||||||||||||||||||||||||
| 114 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 115 | 3 | ( +_DEPENDS ) => $src, | |||||||||||||||||||||||||||||||||||||||||
| 116 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||
| 119 | 3 | __PACKAGE__->_add_roles( qw[ | |||||||||||||||||||||||||||||||||||||||||
| 120 | State::Closure | ||||||||||||||||||||||||||||||||||||||||||
| 121 | Next::ClosedSelf | ||||||||||||||||||||||||||||||||||||||||||
| 122 | Reset::Closure | ||||||||||||||||||||||||||||||||||||||||||
| 123 | ] ); | ||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||
| 127 | # | ||||||||||||||||||||||||||||||||||||||||||
| 128 | # This file is part of Iterator-Flex | ||||||||||||||||||||||||||||||||||||||||||
| 129 | # | ||||||||||||||||||||||||||||||||||||||||||
| 130 | # This software is Copyright (c) 2018 by Smithsonian Astrophysical Observatory. | ||||||||||||||||||||||||||||||||||||||||||
| 131 | # | ||||||||||||||||||||||||||||||||||||||||||
| 132 | # This is free software, licensed under: | ||||||||||||||||||||||||||||||||||||||||||
| 133 | # | ||||||||||||||||||||||||||||||||||||||||||
| 134 | # The GNU General Public License, Version 3, June 2007 | ||||||||||||||||||||||||||||||||||||||||||
| 135 | # | ||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||
| 137 | __END__ | ||||||||||||||||||||||||||||||||||||||||||