blib/lib/Iterator/Flex/Role/Wrap/Return.pm

filter: Statementstmt 96.3% 52 / 54 Branchbran 100% 14 / 14 Conditioncond 45.8% 11 / 24 MC/DCmcdc 18.7% 3 / 16 Subroutinesub 100% 13 / 13 Podpod n/a totaltotal 76.8% 93 / 121 CC 16 SCAR 12.3
CC
16
Cov
84%
__ANON__
5.3
__ANON__
4.3
__ANON__
4.3
CRAP 3.4
« blib/lib/Iterator/Flex/Utils.pm ↑ Summary blib/lib/Iterator/Flex/Cat.pm »
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") }
l!l&&r!l&&!r
7000
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") }
ABresult
1X1
011
000
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
BranchTrueFalseTotal
if (not defined $sentinel) { } 58 12 70
elsif (ref $sentinel) { } 4 8 12
elsif (&Scalar::Util::looks_like_number($sentinel)) { } 4 4 8
35 $wsub = sub {
36 822 ▶ my $self = $_[0] // $wsub;
Subroutine __ANON__: called CC=3 SCAR=11.4
Condition33%1/3
$_[0] // $wsub
l!l&&r!l&&!r
08220
MC/DC0%0/2
$_[0] // $wsub
$_[0] $wsub
Truth table33%1/3
A // B
A= $_[0]B= $wsub
ABresult
1X1
011
000
37 822 my $val = $next->( $self );
38 820 ▶ return !defined $val ? $self->signal_exhaustion : $val;
Branch: 1 branch
BranchTrueFalseTotal
!defined($val) ? : 62 758 820
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
l!l&&r!l&&!r
0440
MC/DC0%0/2
$_[0] // $wsub
$_[0] $wsub
Truth table33%1/3
A // B
A= $_[0]B= $wsub
ABresult
1X1
011
000
48 44 my $val = $next->( $self );
49 44 my $addr = refaddr $val;
50 44 ▶ return defined $addr
Branch: 1 branch
BranchTrueFalseTotal
defined $addr && $addr == $refaddr_sentinel ? : 4 40 44
Condition66%2/3
defined $addr and $addr == $refaddr_sentinel
!ll&&!rl&&r
4004
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
ABresult
0X0
100
111
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
l!l&&r!l&&!r
0420
MC/DC0%0/2
$_[0] // $wsub
$_[0] $wsub
Truth table33%1/3
A // B
A= $_[0]B= $wsub
ABresult
1X1
011
000
59 42 my $val = $next->( $self );
60 42 ▶ return defined $val
Branch: 1 branch
BranchTrueFalseTotal
defined $val && $val == $sentinel ? : 4 38 42
Condition66%2/3
defined $val and $val == $sentinel
!ll&&!rl&&r
0384
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
ABresult
0X0
100
111
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
l!l&&r!l&&!r
0440
MC/DC0%0/2
$_[0] // $wsub
$_[0] $wsub
Truth table33%1/3
A // B
A= $_[0]B= $wsub
ABresult
1X1
011
000
69 44 my $val = $next->( $_[0] );
70 44 ▶ return defined $val
Branch: 1 branch
BranchTrueFalseTotal
defined $val && $val eq $sentinel ? : 4 40 44
Condition66%2/3
defined $val and $val eq $sentinel
!ll&&!rl&&r
0404
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
ABresult
0X0
100
111
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__
« blib/lib/Iterator/Flex/Utils.pm ↑ Summary blib/lib/Iterator/Flex/Cat.pm »