blib/lib/Perl6/Gather.pm

filter: Statementstmt 84.8% 73 / 86 Branchbran 50.0% 10 / 20 Conditioncond 26.3% 5 / 19 MC/DCmcdc 11.1% 1 / 9 Subroutinesub 82.6% 19 / 23 Podpod 0.0% 0 / 4 totaltotal 67.0% 108 / 161 CC 23 SCAR 17.8
CC
23
Cov
70%
import
18.4
gather
8.7
take
4.0
CRAP 5.9
↑ Summary
1 package Perl6::Gather;
2 1 ▶use Perl6::Export;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 0 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=1.5
Subroutine BEGIN: called CC=2 SCAR=9.7
Subroutine BEGIN: called CC=1 SCAR=1.5
Subroutine _import_16ca23858bb28246dfa2fcc876a8131f: called CC=1 SCAR=1.5
Subroutine import: called CC=8 SCAR=29.1
Branch: 3 branches
BranchTrueFalseTotal
if ($i < @_) 0 1 1
if (not ref $_ and /^[:\$&%\@]?(\w+)$/ and exists $EXPORT{$1} || exists $EXPORT_TAGS{$1}) 0 0 0
unless @exports 1 0 1
Condition9%1/11
$EXPORT_TAGS{"MANDATORY"} ||= []
l!l
01
not ref $_ and /^[:\$&%\@]?(\w+)$/ and exists $EXPORT{$1} || exists $EXPORT_TAGS{$1}
!ll&&!rl&&r
000
not ref $_ and /^[:\$&%\@]?(\w+)$/
!ll&&!rl&&r
000
exists $EXPORT{$1} or exists $EXPORT_TAGS{$1}
l!l&&r!l&&!r
000
MC/DC0%0/1
$EXPORT_TAGS{"MANDATORY"} ||= []
$EXPORT_TAGS{"MANDATORY"}
MC/DC0%0/4
not ref $_ and /^[:\$&%\@]?(\w+)$/ and exists $EXPORT{$1} || exists $EXPORT_TAGS{$1}
not ref $_ /^[:\$&%\@]?(\w+)$/ exists $EXPORT{$1} exists $EXPORT_TAGS{$1}
Truth table50%1/2
A
A= $EXPORT_TAGS{"MANDATORY"}
Aresult
11
00
Truth table0%0/5
not(A) and B and C or D
A= not ref $_B= /^[:\$&%\@]?(\w+)$/C= exists $EXPORT{$1}D= exists $EXPORT_TAGS{$1}
ABCDresult
0XXX0
10XX0
11000
111X1
11011
4  
5 1 our $VERSION = '0.42';
6  
7 1 my %gatherers;
8  
9 1 ▶sub gather(&) is export(:DEFAULT) {
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=2 SCAR=6.9
Subroutine gather: called CC=7 SCAR=21.6
Pod undocumented
10 4 ▶ croak "Useless use of 'gather' in void context" unless defined wantarray;
Branch: 1 branch
BranchTrueFalseTotal
unless defined wantarray 0 4 4
11 4 my ($code) = @_;
12 4 my $caller = caller;
13 4 local @_;
14 4 push @{$gatherers{$caller}}, bless \@_, 'Perl6::Gather::MagicArrayRef';
15 die $@
16 4 ▶ if !eval{ &$code } && $@ && !UNIVERSAL::isa($@, Perl6::Gather::Break);
Branch: 1 branch
BranchTrueFalseTotal
if not eval { do { &$code } } and $@ and not UNIVERSAL::isa($@, "Perl6::Gather::Break") 0 4 4
Condition33%2/6
not eval { do { &$code } } and $@ and not UNIVERSAL::isa($@, "Perl6::Gather::Break")
!ll&&!rl&&r
400
not eval { do { &$code } } and $@
!ll&&!rl&&r
400
MC/DC0%0/3
not eval { do { &$code } } and $@ and not UNIVERSAL::isa($@, "Perl6::Gather::Break")
not eval { do { &$code } } $@ not UNIVERSAL::isa($@, "Perl6::Gather::Break")
Truth table25%1/4
not(A) and B and not(C)
A= not eval { do { &$code } }B= $@C= not UNIVERSAL::isa($@, "Perl6::Gather::Break")
ABCresult
0XX0
10X0
1100
1111
17 4 ▶ return @{pop @{$gatherers{$caller}}} if wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 4 0 4
18 0 ▶ return pop @{$gatherers{$caller}} if defined wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if defined wantarray 0 0 0
19 }
20  
21 1 ▶sub gathered() is export(:DEFAULT) {
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=2 SCAR=6.9
Subroutine gathered: called CC=2 SCAR=6.9
Pod undocumented
22 4 my $caller = caller;
23 4 ▶ croak "Call to gathered not inside a gather" unless @{$gatherers{$caller}};
Branch: 1 branch
BranchTrueFalseTotal
unless @{$gatherers{$caller};} 1 3 4
24 3 return $gatherers{$caller}[-1];
25 }
26  
27 1 ▶sub take(@) is export(:DEFAULT) {
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=2 SCAR=6.9
Subroutine take: called CC=4 SCAR=13.9
Pod undocumented
28 33 ▶ @_ = $_ unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 33 33
29 33 my $caller = caller;
30 33 ▶ croak "Call to take not inside a gather block"
Branch: 1 branch
BranchTrueFalseTotal
unless ((caller 3)[3] || "") eq "Perl6::Gather::gather" 1 32 33
Condition100%2/2
(caller 3)[3] || ''
l!l
321
MC/DC100%1/1
(caller 3)[3] || ''
(caller 3)[3]
Truth table100%2/2
A
A= (caller 3)[3]
Aresult
11
00
31 unless ((caller 3)[3]||"") eq 'Perl6::Gather::gather';
32 32 push @{$gatherers{$caller}[-1]}, @_;
33 32 return 0+@_;
34 }
35  
36 1 my $breaker = bless [], 'Perl6::Gather::Break';
37  
38 1 ▶sub break() is export(:DEFAULT) {
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=2 SCAR=6.9
Subroutine break: not called CC=1 SCAR=0.0
Pod undocumented
39 0 die $breaker;
40 }
41  
42 package Perl6::Gather::MagicArrayRef;
43  
44 use overload
45 3 ▶ 'bool' => sub { @{$_[0]} > 0 },
Subroutine BEGIN: called CC=1 SCAR=1.5
Subroutine __ANON__: called CC=1 SCAR=0.0
46 0 ▶ '0+' => sub { @{$_[0]} + 0 },
Subroutine __ANON__: not called CC=1 SCAR=6.9
47 0 ▶ '""' => sub { join "", @{$_[0]} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
48 0 ▶ '~' => sub { join "", @{$_[0]} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
49 1 fallback => 1;
50 ;
51  
52 1 1;
53 __END__
↑ Summary