Tree/Iterator.pm

filter: Statementstmt 98.5% 67 / 68 Branchbran 90.0% 18 / 20 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 9 / 9 Podpod 0.0% 0 / 2 totaltotal 93.2% 97 / 104 CC 14 SCAR 18.4
CC
14
Cov
96%
_next_subtest
11.0
new
2.0
next
2.0
CRAP 6.3
« Tree.pm ↑ Summary
1 package TAP::Tree::Iterator;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use v5.10.1;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 4 ▶sub new {
Subroutine new: called CC=2 SCAR=7.1
Pod undocumented
11 4 my $class = shift;
12 4 my %params = @_;
13  
14 4 my ( $pkg, undef, undef ) = caller;
15 4 ▶ if ( $pkg ne 'TAP::Tree' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pkg ne "TAP::Tree") 0 4 4
16 0 croak "Invalid call! This module must be called from inside TAP::Tree.";
17 }
18  
19 my $self = {
20 tap_tree => $params{tap_tree},
21 subtest => $params{subtest},
22  
23 4 index_recursive => [],
24 index_testline => 0,
25 };
26  
27 4 bless $self, $class;
28  
29 4 return $self;
30 }
31  
32 24 ▶sub next {
Subroutine next: called CC=2 SCAR=6.9
Pod undocumented
33 24 my $self = shift;
34  
35 24 ▶ my $next = ( $self->{subtest} ) ? $self->_next_subtest : $self->_next;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'subtest'} ? : 21 3 24
36  
37 24 return $next;
38 }
39  
40 21 ▶sub _next_subtest {
Subroutine _next_subtest: called CC=11 SCAR=24.0
41 21 my $self = shift;
42  
43 21 ▶ return if ( ! defined $self->{index_testline} );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"index_testline"} 2 19 21
44  
45 # get current test
46 my $test = {
47 plan => $self->{tap_tree}{plan},
48 testline => $self->{tap_tree}{testline},
49 19 };
50  
51 19 for my $index ( @{ $self->{index_recursive} } ) {
52 17 my $current = $test->{testline}[$index]{subtest};
53  
54 17 $test = $current;
55 }
56  
57 # get current testline
58 my $testline = ( defined $test->{testline}[$self->{index_testline}] ) ?
59 19 ▶ $test->{testline}[$self->{index_testline}] : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $test->{'testline'}[$self->{'index_testline'}] ? : 19 0 19
60  
61 my $next = {
62 test => $test,
63 testline => $testline,
64 19 indent => scalar @{ $self->{index_recursive} },
65 };
66  
67 # set next index
68 19 ▶ if ( $testline && $testline->{subtest} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($testline and $testline->{"subtest"}) 8 11 19
Condition66%2/3
$testline and $testline->{"subtest"}
!ll&&!rl&&r
0118
MC/DC50%1/2
$testline and $testline->{"subtest"}
$testline $testline->{"subtest"}
Truth table66%2/3
A and B
A= $testlineB= $testline->{"subtest"}
ABresult
0X0
100
111
69 8 push @{ $self->{index_recursive} }, $self->{index_testline};
70 8 $self->{index_testline} = 0;
71  
72 8 return $next;
73 }
74  
75 11 ▶ if ( defined $test->{testline}[$self->{index_testline} + 1 ] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $test->{"testline"}[$self->{"index_testline"} + 1]) 4 7 11
76 4 $self->{index_testline} += 1;
77 4 return $next;
78 }
79  
80 7 my $found;
81 7 ▶ while ( @{ $self->{index_recursive} } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->{"index_recursive"};}) 8 3 11
82 8 my $index_next = pop @{ $self->{index_recursive} };
83  
84 my $nexttest = {
85 testline => $self->{tap_tree}{testline},
86 8 };
87  
88 8 for my $i ( @{ $self->{index_recursive} } ) {
89 5 my $current = $nexttest->{testline}[$i]{subtest};
90  
91 5 $nexttest = $current;
92 }
93  
94 8 ▶ if ( defined $nexttest->{testline}[$index_next + 1] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $nexttest->{"testline"}[$index_next + 1]) 4 4 8
95 4 $found = $index_next + 1;
96 4 last;
97 }
98 }
99  
100 7 ▶ if ( $found ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($found) { } 4 3 7
101 4 $self->{index_testline} = $found;
102 } else {
103 3 $self->{index_testline} = undef;
104 }
105  
106 7 return $next;
107 }
108  
109 3 ▶sub _next {
Subroutine _next: called CC=2 SCAR=6.9
110 3 my $self = shift;
111  
112 my $test = {
113 plan => $self->{tap_tree}{plan},
114 testline => $self->{tap_tree}{testline},
115 3 };
116
117 3 ▶ if ( defined $self->{tap_tree}{testline}[$self->{index_testline}] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'tap_tree'}{'testline'}[$self->{'index_testline'}]) { } 2 1 3
118 2 my $testline = $self->{tap_tree}{testline}[$self->{index_testline}];
119  
120 2 $self->{index_testline}++;
121
122 2 return { test => $test, testline => $testline, indent => 0 };
123 } else {
124 1 return;
125 }
126 }
127  
128 3 1;
129  
130 __END__
« Tree.pm ↑ Summary