blib/lib/Test2/API/Stack.pm

filter: Statementstmt 100% 60 / 60 Branchbran 100% 20 / 20 Conditioncond 72.7% 8 / 11 MC/DCmcdc 50.0% 3 / 6 Subroutinesub 100% 15 / 15 Podpod 87.5% 7 / 8 totaltotal 94.1% 113 / 120 CC 16 SCAR 12.9
CC
16
Cov
97%
new_hub
8.1
__ANON__
4.0
top
2.0
CRAP 3.6
« blib/lib/Test2/Tools/Tiny.pm ↑ Summary blib/lib/Test2/Compare/OrderedSubset.pm »
1 package Test2::API::Stack;
2 455 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 455 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 455 our $VERSION = '1.302226';
6  
7  
8 455 ▶use Test2::Hub();
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 455 ▶use Carp qw/confess/;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 612 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
13 612 my $class = shift;
14 612 return bless [], $class;
15 }
16  
17 1061 ▶sub new_hub {
Subroutine new_hub: called CC=8 SCAR=20.9
Pod documented
18 1061 my $self = shift;
19 1061 my %params = @_;
20  
21 1061 ▶ my $class = delete $params{class} || 'Test2::Hub';
Condition100%2/2
delete $params{'class'} || 'Test2::Hub'
l!l
523538
MC/DC100%1/1
delete $params{'class'} || 'Test2::Hub'
delete $params{'class'}
Truth table100%2/2
A
A= delete $params{'class'}
Aresult
11
00
22  
23 1061 my $hub = $class->new(%params);
24  
25 1061 ▶ if (@$self) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$self) { } 541 520 1061
26 541 $hub->inherit($self->[-1], %params);
27 }
28 else {
29 520 require Test2::API;
30 $hub->format(Test2::API::test2_formatter()->new_root)
31 520 ▶ unless $hub->format || exists($params{formatter});
Branch: 1 branch
BranchTrueFalseTotal
unless $hub->format or exists $params{"formatter"} 473 47 520
Condition66%2/3
$hub->format or exists $params{"formatter"}
l!l&&r!l&&!r
470473
MC/DC50%1/2
$hub->format or exists $params{"formatter"}
$hub->format exists $params{"formatter"}
Truth table66%2/3
A or B
A= $hub->formatB= exists $params{"formatter"}
ABresult
1X1
011
000
32  
33 520 my $ipc = Test2::API::test2_ipc();
34 520 ▶ if ($ipc && !$hub->ipc && !exists($params{ipc})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ipc and not $hub->ipc and not exists $params{"ipc"}) 116 404 520
Condition66%4/6
$ipc and not $hub->ipc and not exists $params{"ipc"}
!ll&&!rl&&r
4040116
$ipc and not $hub->ipc
!ll&&!rl&&r
4040116
MC/DC33%1/3
$ipc and not $hub->ipc and not exists $params{"ipc"}
$ipc not $hub->ipc not exists $params{"ipc"}
Truth table50%2/4
A and not(B) and not(C)
A= $ipcB= not $hub->ipcC= not exists $params{"ipc"}
ABCresult
0XX0
10X0
1100
1111
35 116 $hub->set_ipc($ipc);
36 116 $ipc->add_hub($hub->hid);
37 }
38 }
39  
40 1061 push @$self => $hub;
41  
42 1061 $hub;
43 }
44  
45 4339 ▶sub top {
Subroutine top: called CC=2 SCAR=6.9
Pod documented
46 4339 my $self = shift;
47 4339 ▶ return $self->new_hub unless @$self;
Branch: 1 branch
BranchTrueFalseTotal
unless @$self 473 3866 4339
48 3866 return $self->[-1];
49 }
50  
51 2 ▶sub peek {
Subroutine peek: called CC=2 SCAR=6.9
Pod documented
52 2 my $self = shift;
53 2 ▶ return @$self ? $self->[-1] : undef;
Branch: 1 branch
BranchTrueFalseTotal
@$self ? : 1 1 2
54 }
55  
56 1 ▶sub cull {
Subroutine cull: called CC=2 SCAR=6.9
Pod documented
57 1 my $self = shift;
58 1 $_->cull for reverse @$self;
59 }
60  
61 618 ▶sub all {
Subroutine all: called CC=1 SCAR=0.0
Pod documented
62 618 my $self = shift;
63 618 return @$self;
64 }
65  
66 456 ▶sub root {
Subroutine root: called CC=2 SCAR=6.9
Pod undocumented
67 456 my $self = shift;
68 456 ▶ return unless @$self;
Branch: 1 branch
BranchTrueFalseTotal
unless @$self 2 454 456
69 454 return $self->[0];
70 }
71  
72 2 ▶sub clear {
Subroutine clear: called CC=1 SCAR=0.0
Pod documented
73 2 my $self = shift;
74 2 @$self = ();
75 }
76  
77 # Do these last without keywords in order to prevent them from getting used
78 # when we want the real push/pop.
79  
80 {
81 455 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
82  
83 663 ▶ *push = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
84 663 my $self = shift;
85 663 my ($hub) = @_;
86 663 ▶ $hub->inherit($self->[-1]) if @$self;
Branch: 1 branch
BranchTrueFalseTotal
if @$self 662 1 663
87 663 push @$self => $hub;
88 455 };
89  
90 1150 ▶ *pop = sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
91 1150 my $self = shift;
92 1150 my ($hub) = @_;
93 1150 ▶ confess "No hubs on the stack"
Branch: 1 branch
BranchTrueFalseTotal
unless @$self 1 1149 1150
94 unless @$self;
95 1149 ▶ confess "You cannot pop the root hub"
Branch: 1 branch
BranchTrueFalseTotal
if 1 == @$self 1 1148 1149
96 if 1 == @$self;
97 1148 ▶ confess "Hub stack mismatch, attempted to pop incorrect hub"
Branch: 1 branch
BranchTrueFalseTotal
unless $self->[-1] == $hub 1 1147 1148
98 unless $self->[-1] == $hub;
99 1147 pop @$self;
100 455 };
101 }
102  
103 455 1;
104  
105 __END__
« blib/lib/Test2/Tools/Tiny.pm ↑ Summary blib/lib/Test2/Compare/OrderedSubset.pm »