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

filter: Statementstmt 86.5% 71 / 82 Branchbran 82.1% 23 / 28 Conditioncond 40.7% 11 / 27 MC/DCmcdc 11.1% 2 / 18 Subroutinesub 93.7% 15 / 16 Podpod n/a totaltotal 71.3% 122 / 171 CC 24 SCAR 18.2
CC
24
Cov
77%
__ANON__
12.7
__ANON__
12.0
__ANON__
5.1
CRAP 6.1
« blib/lib/Iterator/Flex/Permute.pm ↑ Summary blib/lib/Iterator/Flex/Array.pm »
1 package Iterator::Flex::Role::Wrap::Throw;
2  
3 # ABSTRACT: Role to add throw on exhaustion to an iterator which adapts another iterator
4  
5 4 ▶use v5.28;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 4 our $VERSION = '0.33';
10  
11 4 ▶use List::Util 'first';
Subroutine BEGIN: called CC=1 SCAR=0.0
12 4 ▶use Iterator::Flex::Utils qw( INPUT_EXHAUSTION PASSTHROUGH );
Subroutine BEGIN: called CC=1 SCAR=0.0
13 4 ▶use Ref::Util qw( is_ref is_blessed_ref is_regexpref is_arrayref is_coderef );
Subroutine BEGIN: called CC=1 SCAR=0.0
14 4 ▶use Role::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 4 ▶use experimental 'signatures';
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 4 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 ▶around _construct_next => sub ( $orig, $class, $ipar, $gpar ) {
Subroutine __ANON__: called CC=10 SCAR=25.4
20  
21 18 my $next = $class->$orig( $ipar, $gpar );
22  
23 my $exception = (
24 18 ▶ $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
1800
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
25 0 require Iterator::Flex::Failure;
26 0 Iterator::Flex::Failure::parameter->throw(
27 q{internal error: input exhaustion policy was not registered} );
28 }
29 )->[1];
30  
31 18 my $wsub;
32  
33 ## no critic ( CascadingIfElse )
34 18 ▶ if ( !defined $exception ) {
Branch: 5 branches
BranchTrueFalseTotal
if (not defined $exception) { } 6 12 18
elsif (not Ref::Util::XS::is_ref($exception) and $exception eq 'passthrough') { } 0 12 12
elsif (not Ref::Util::XS::is_ref($exception) or Ref::Util::XS::is_arrayref($exception)) { } 4 8 12
elsif (Ref::Util::XS::is_regexpref($exception)) { } 4 4 8
elsif (Ref::Util::XS::is_coderef($exception)) { } 4 0 4
35  
36 $wsub = sub {
37 58 ▶ my $self = $_[0] // $wsub;
Subroutine __ANON__: called CC=3 SCAR=11.3
Condition33%1/3
$_[0] // $wsub
l!l&&r!l&&!r
0580
MC/DC0%0/2
$_[0] // $wsub
$_[0] $wsub
Truth table33%1/3
A // B
A= $_[0]B= $wsub
ABresult
1X1
011
000
38 58 my $val = eval { $next->( $self ) };
39 58 ▶ return $@ ne q{} ? $self->signal_exhaustion( $@ ) : $val;
Branch: 1 branch
BranchTrueFalseTotal
$@ ne '' ? : 6 52 58
40 6 };
41 }
42  
43 ▶ elsif ( !is_ref( $exception ) && $exception eq PASSTHROUGH ) {
Condition66%2/3
not Ref::Util::XS::is_ref($exception) and $exception eq "passthrough"
!ll&&!rl&&r
840
MC/DC0%0/2
not Ref::Util::XS::is_ref($exception) and $exception eq "passthrough"
not Ref::Util::XS::is_ref($exception) $exception eq "passthrough"
Truth table66%2/3
not(A) and B
A= not Ref::Util::XS::is_ref($exception)B= $exception eq "passthrough"
ABresult
0X0
100
111
44  
45 $wsub = sub {
46 0 ▶ my $self = $_[0] // $wsub;
Subroutine __ANON__: not called CC=3 SCAR=24.8
Condition0%0/3
$_[0] // $wsub
l!l&&r!l&&!r
000
MC/DC0%0/2
$_[0] // $wsub
$_[0] $wsub
Truth table0%0/3
A // B
A= $_[0]B= $wsub
ABresult
1X1
011
000
47 0 my $val = eval { $next->( $self ) };
48 0 ▶ return $@ ne q{} ? $self->signal_exhaustion( $@ ) : $val;
Branch: 1 branch
BranchTrueFalseTotal
$@ ne '' ? : 0 0 0
49 0 };
50 }
51  
52 ▶ elsif ( !is_ref( $exception ) || is_arrayref( $exception ) ) {
Condition66%2/3
not Ref::Util::XS::is_ref($exception) or Ref::Util::XS::is_arrayref($exception)
l!l&&r!l&&!r
408
MC/DC50%1/2
not Ref::Util::XS::is_ref($exception) or Ref::Util::XS::is_arrayref($exception)
not Ref::Util::XS::is_ref($exception) Ref::Util::XS::is_arrayref($exception)
Truth table66%2/3
not(A) or B
A= not Ref::Util::XS::is_ref($exception)B= Ref::Util::XS::is_arrayref($exception)
ABresult
1X1
011
000
53 4 ▶ $exception = [$exception]
Branch: 1 branch
BranchTrueFalseTotal
unless Ref::Util::XS::is_arrayref($exception) 4 0 4
54 unless is_arrayref( $exception );
55  
56 $wsub = sub {
57 36 ▶ my $self = $_[0] // $wsub;
Subroutine __ANON__: called CC=5 SCAR=16.3
Condition33%1/3
$_[0] // $wsub
l!l&&r!l&&!r
0360
MC/DC0%0/2
$_[0] // $wsub
$_[0] $wsub
Truth table33%1/3
A // B
A= $_[0]B= $wsub
ABresult
1X1
011
000
58 36 my $val = eval { $next->( $self ) };
59 36 ▶ if ( $@ ne q{} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@ ne "") 4 32 36
60 4 my $e = $@;
61 return $self->signal_exhaustion( $e )
62 4 ▶ if is_blessed_ref( $e ) && first { $e->isa( $_ ) } @$exception;
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if Ref::Util::XS::is_blessed_ref($e) and &first(sub { $e->isa($_); } , @$exception) 2 2 4
Condition66%2/3
Ref::Util::XS::is_blessed_ref($e) and &first(sub { $e->isa($_); } , @$exception)
!ll&&!rl&&r
202
MC/DC50%1/2
Ref::Util::XS::is_blessed_ref($e) and &first(sub { $e->isa($_); } , @$exception)
Ref::Util::XS::is_blessed_ref($e) &first(sub { $e->isa($_); } , @$exception)
Truth table66%2/3
A and B
A= Ref::Util::XS::is_blessed_ref($e)B= &first(sub { $e->isa($_); } , @$exception)
ABresult
0X0
100
111
63 2 die $e;
64 }
65 32 return $val;
66 4 };
67 }
68  
69 elsif ( is_regexpref( $exception ) ) {
70  
71 $wsub = sub {
72 36 ▶ my $self = $_[0] // $wsub;
Subroutine __ANON__: called CC=4 SCAR=14.0
Condition33%1/3
$_[0] // $wsub
l!l&&r!l&&!r
0360
MC/DC0%0/2
$_[0] // $wsub
$_[0] $wsub
Truth table33%1/3
A // B
A= $_[0]B= $wsub
ABresult
1X1
011
000
73 36 my $val = eval { $next->( $self ) };
74 36 ▶ if ( $@ ne q{} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@ ne "") 4 32 36
75 4 my $e = $@;
76 4 ▶ return $self->signal_exhaustion( $e ) if $e =~ $exception;
Branch: 1 branch
BranchTrueFalseTotal
if $e =~ /$exception/u 2 2 4
77 2 die $e;
78 }
79 32 return $val;
80 4 };
81 }
82  
83 elsif ( is_coderef( $exception ) ) {
84  
85 $wsub = sub {
86 36 ▶ my $self = $_[0] // $wsub;
Subroutine __ANON__: called CC=4 SCAR=14.0
Condition33%1/3
$_[0] // $wsub
l!l&&r!l&&!r
0360
MC/DC0%0/2
$_[0] // $wsub
$_[0] $wsub
Truth table33%1/3
A // B
A= $_[0]B= $wsub
ABresult
1X1
011
000
87 36 my $val = eval { $next->( $self ) };
88 36 ▶ if ( $@ ne q{} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@ ne "") 4 32 36
89 4 my $e = $@;
90 4 ▶ return $self->signal_exhaustion( $e ) if $exception->( $e );
Branch: 1 branch
BranchTrueFalseTotal
if &$exception($e) 2 2 4
91 2 die $e;
92 }
93 32 return $val;
94 4 };
95 }
96  
97 else {
98 0 require Iterator::Flex::Failure;
99 0 require Scalar::Util;
100 0 Iterator::Flex::Failure::parameter->throw(
101 0 "internal error: unknown type for input exhaustion policy: ${ \Scalar::Util::reftype( $exception ) }",
102 );
103  
104 }
105  
106  
107 # create a second reference to $wsub, before we weaken it,
108 # otherwise it will lose its contents, as it would be the only
109 # reference.
110  
111 18 my $sub = $wsub;
112 18 Scalar::Util::weaken( $wsub );
113 18 return $sub;
114 4 };
115  
116 4 requires 'signal_exhaustion';
117  
118 4 1;
119  
120 #
121 # This file is part of Iterator-Flex
122 #
123 # This software is Copyright (c) 2018 by Smithsonian Astrophysical Observatory.
124 #
125 # This is free software, licensed under:
126 #
127 # The GNU General Public License, Version 3, June 2007
128 #
129  
130 __END__
« blib/lib/Iterator/Flex/Permute.pm ↑ Summary blib/lib/Iterator/Flex/Array.pm »