| 1 | package Iterator::Flex::Role::Wrap::Return; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | # ABSTRACT: wrap imported iterator which returns a sentinel on exhaustion | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 15 | ▶ | use v5.28; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 15 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 15 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 15 | our $VERSION = '0.33'; | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 15 | ▶ | use Iterator::Flex::Utils qw( :default INPUT_EXHAUSTION ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 15 | ▶ | use Scalar::Util; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 15 | ▶ | use Role::Tiny; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 15 | ▶ | use experimental 'signatures'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 15 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | ▶ | around _construct_next => sub ( $orig, $class, $ipar, $gpar ) { | |||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.7
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 70 | my $next = $class->$orig( $ipar, $gpar ); | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | # this will be weakened latter. | ||||||||||||||||||||||||||||
| 23 | 70 | my $wsub; | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | my $sentinel = ( | ||||||||||||||||||||||||||||
| 26 | 70 | ▶ | $gpar->{ +INPUT_EXHAUSTION } // do { | ||||||||||||||||||||||||||
|
Condition33%1/3
$gpar->{"input_exhaustion"} // do {
require Iterator::Flex::Failure;
"Iterator::Flex::Failure::parameter"->throw("internal error: input exhaustion policy was not registered")
}
MC/DC0%0/2
$gpar->{"input_exhaustion"} // do {
require Iterator::Flex::Failure;
"Iterator::Flex::Failure::parameter"->throw("internal error: input exhaustion policy was not registered")
}
$gpar->{"input_exhaustion"}
do {
require Iterator::Flex::Failure;
"Iterator::Flex::Failure::parameter"->throw("internal error: input exhaustion policy was not registered")
}
Truth table33%1/3
A // B
A= $gpar->{"input_exhaustion"}B= do {
require Iterator::Flex::Failure;
"Iterator::Flex::Failure::parameter"->throw("internal error: input exhaustion policy was not registered")
}
| |||||||||||||||||||||||||||||
| 27 | 0 | require Iterator::Flex::Failure; | |||||||||||||||||||||||||||
| 28 | 0 | Iterator::Flex::Failure::parameter->throw( | |||||||||||||||||||||||||||
| 29 | q{internal error: input exhaustion policy was not registered} ); | ||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | )->[1]; | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | # undef | ||||||||||||||||||||||||||||
| 34 | 70 | ▶ | if ( !defined $sentinel ) { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 35 | $wsub = sub { | ||||||||||||||||||||||||||||
| 36 | 822 | ▶ | my $self = $_[0] // $wsub; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.4
Condition33%1/3
$_[0] // $wsub
MC/DC0%0/2
$_[0] // $wsub
$_[0]
$wsub
Truth table33%1/3
A // B
A= $_[0]B= $wsub
| |||||||||||||||||||||||||||||
| 37 | 822 | my $val = $next->( $self ); | |||||||||||||||||||||||||||
| 38 | 820 | ▶ | return !defined $val ? $self->signal_exhaustion : $val; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | 58 | }; | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | # reference | ||||||||||||||||||||||||||||
| 43 | elsif ( ref $sentinel ) { | ||||||||||||||||||||||||||||
| 44 | 4 | my $refaddr_sentinel = refaddr $sentinel; | |||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | $wsub = sub { | ||||||||||||||||||||||||||||
| 47 | 44 | ▶ | my $self = $_[0] // $wsub; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=14.5
Condition33%1/3
$_[0] // $wsub
MC/DC0%0/2
$_[0] // $wsub
$_[0]
$wsub
Truth table33%1/3
A // B
A= $_[0]B= $wsub
| |||||||||||||||||||||||||||||
| 48 | 44 | my $val = $next->( $self ); | |||||||||||||||||||||||||||
| 49 | 44 | my $addr = refaddr $val; | |||||||||||||||||||||||||||
| 50 | 44 | ▶ | return defined $addr | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $addr and $addr == $refaddr_sentinel
MC/DC50%1/2
defined $addr and $addr == $refaddr_sentinel
defined $addr
$addr == $refaddr_sentinel
Truth table66%2/3
A and B
A= defined $addrB= $addr == $refaddr_sentinel
| |||||||||||||||||||||||||||||
| 51 | && $addr == $refaddr_sentinel ? $self->signal_exhaustion : $val; | ||||||||||||||||||||||||||||
| 52 | 4 | }; | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | # number | ||||||||||||||||||||||||||||
| 56 | elsif ( Scalar::Util::looks_like_number( $sentinel ) ) { | ||||||||||||||||||||||||||||
| 57 | $wsub = sub { | ||||||||||||||||||||||||||||
| 58 | 42 | ▶ | my $self = $_[0] // $wsub; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=14.6
Condition33%1/3
$_[0] // $wsub
MC/DC0%0/2
$_[0] // $wsub
$_[0]
$wsub
Truth table33%1/3
A // B
A= $_[0]B= $wsub
| |||||||||||||||||||||||||||||
| 59 | 42 | my $val = $next->( $self ); | |||||||||||||||||||||||||||
| 60 | 42 | ▶ | return defined $val | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $val and $val == $sentinel
MC/DC50%1/2
defined $val and $val == $sentinel
defined $val
$val == $sentinel
Truth table66%2/3
A and B
A= defined $valB= $val == $sentinel
| |||||||||||||||||||||||||||||
| 61 | && $val == $sentinel ? $self->signal_exhaustion : $val; | ||||||||||||||||||||||||||||
| 62 | 4 | }; | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | # string | ||||||||||||||||||||||||||||
| 66 | else { | ||||||||||||||||||||||||||||
| 67 | $wsub = sub { | ||||||||||||||||||||||||||||
| 68 | 44 | ▶ | my $self = $_[0] // $wsub; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=14.6
Condition33%1/3
$_[0] // $wsub
MC/DC0%0/2
$_[0] // $wsub
$_[0]
$wsub
Truth table33%1/3
A // B
A= $_[0]B= $wsub
| |||||||||||||||||||||||||||||
| 69 | 44 | my $val = $next->( $_[0] ); | |||||||||||||||||||||||||||
| 70 | 44 | ▶ | return defined $val | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $val and $val eq $sentinel
MC/DC50%1/2
defined $val and $val eq $sentinel
defined $val
$val eq $sentinel
Truth table66%2/3
A and B
A= defined $valB= $val eq $sentinel
| |||||||||||||||||||||||||||||
| 71 | && $val eq $sentinel ? $self->signal_exhaustion : $val; | ||||||||||||||||||||||||||||
| 72 | 4 | }; | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | # create a second reference to $wsub, before we weaken it, | ||||||||||||||||||||||||||||
| 76 | # otherwise it will lose its contents, as it would be the only | ||||||||||||||||||||||||||||
| 77 | # reference. | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 70 | my $sub = $wsub; | |||||||||||||||||||||||||||
| 80 | 70 | Scalar::Util::weaken( $wsub ); | |||||||||||||||||||||||||||
| 81 | 70 | return $sub; | |||||||||||||||||||||||||||
| 82 | 15 | }; | |||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 15 | requires 'signal_exhaustion'; | |||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 15 | 1; | |||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | # | ||||||||||||||||||||||||||||
| 89 | # This file is part of Iterator-Flex | ||||||||||||||||||||||||||||
| 90 | # | ||||||||||||||||||||||||||||
| 91 | # This software is Copyright (c) 2018 by Smithsonian Astrophysical Observatory. | ||||||||||||||||||||||||||||
| 92 | # | ||||||||||||||||||||||||||||
| 93 | # This is free software, licensed under: | ||||||||||||||||||||||||||||
| 94 | # | ||||||||||||||||||||||||||||
| 95 | # The GNU General Public License, Version 3, June 2007 | ||||||||||||||||||||||||||||
| 96 | # | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | __END__ | ||||||||||||||||||||||||||||