ODS/Iterator.pm

filter: Statementstmt 78.0% 71 / 91 Branchbran 83.3% 15 / 18 Conditioncond 54.5% 6 / 11 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 78.9% 15 / 19 Podpod 0.0% 0 / 16 totaltotal 66.4% 107 / 161 CC 18 SCAR 10.7
CC
18
Cov
77%
flat
6.0
prev
4.5
find
4.0
CRAP 2.9
« ODS/Table/Column/Base.pm ↑ Summary ODS/Table/Row.pm »
1 package ODS::Iterator;
2  
3 1 ▶use YAOO;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 auto_build;
6  
7 1 has table => isa(object);
8  
9 1 has next_index => isa(integer(0));
10  
11 1 has prev_index => isa(integer(0));
12  
13 use overload
14 1 ▶ '@{}' => sub { $_[0]->all };
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
15  
16 # The following sub routines only manipulate the data that is in "memory"
17 # to query a larger dataset you should use the storage api/sub routines.
18  
19 sub all {
20 24 ▶ return $_[0]->table->rows;
Subroutine all: called CC=1 SCAR=0.0
Pod undocumented
21 }
22  
23 sub first {
24 1 ▶ return $_[0]->table->rows->[0];
Subroutine first: called CC=1 SCAR=0.0
Pod undocumented
25 }
26  
27 sub last {
28 1 ▶ return $_[0]->table->rows->[-1];
Subroutine last: called CC=1 SCAR=0.0
Pod undocumented
29 }
30  
31 sub next {
32 4 ▶ my $next = $_[0]->table->rows->[$_[0]->next_index];
Subroutine next: called CC=3 SCAR=11.1
Pod undocumented
33 4 $_[0]->next_index($_[0]->next_index + 1);
34 4 ▶ return $next ? $next : $_[0]->next_index(0) && 0;
Branch: 1 branch
BranchTrueFalseTotal
$next ? : 3 1 4
Condition50%1/2
$_[0]->next_index(0) and 0
!ll
10
MC/DC0%0/1
$_[0]->next_index(0) and 0
$_[0]->next_index(0)
Truth table50%1/2
A
A= $_[0]->next_index(0)
Aresult
00
11
35 }
36  
37 sub prev {
38 4 ▶ if (not defined $_[0]->prev_index ) {
Subroutine prev: called CC=4 SCAR=15.0
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $_[0]->prev_index) 0 4 4
39 0 $_[0]->prev_index(scalar @{ $_[0] });
40 }
41 4 my $prev = $_[0]->table->rows->[$_[0]->prev_index];
42 4 $_[0]->prev_index($_[0]->prev_index + 1);
43 4 ▶ return $prev ? $prev : $_[0]->prev_index(scalar @{$_[0]}) && 0;
Branch: 1 branch
BranchTrueFalseTotal
$prev ? : 3 1 4
Condition50%1/2
$_[0]->prev_index(scalar @{$_[0];}) and 0
!ll
01
MC/DC0%0/1
$_[0]->prev_index(scalar @{$_[0];}) and 0
$_[0]->prev_index(scalar @{$_[0];})
Truth table50%1/2
A
A= $_[0]->prev_index(scalar @{$_[0];})
Aresult
00
11
44 }
45  
46 sub flat {
47 0 ▶ my ($self, $keyfield) = @_;
Subroutine flat: not called CC=2 SCAR=17.9
Pod undocumented
48 0 my @array;
49 0 for my $row (@{ $self }) {
50 0 push @array, {%{$row}};
51 }
52 0 return \@array;
53 }
54  
55 sub array_to_hash {
56 1 ▶ my ($self, $keyfield) = @_;
Subroutine array_to_hash: called CC=3 SCAR=11.2
Pod undocumented
57 1 ▶ $keyfield ||= $self->table->keyfield;
Condition33%1/3
$keyfield ||= $self->table->keyfield
l!l&&r!l&&!r
010
MC/DC0%0/2
$keyfield ||= $self->table->keyfield
$keyfield $self->table->keyfield
Truth table33%1/3
A ||= B
A= $keyfieldB= $self->table->keyfield
ABresult
1X1
011
000
58 1 my %hash;
59 1 for my $row (@{ $self }) {
60 3 $hash{$row->{$keyfield}} = {%{$row}};
61 }
62 1 return \%hash;
63 }
64  
65 sub foreach {
66 1 ▶ my ($self, $cb) = @_;
Subroutine foreach: called CC=3 SCAR=11.0
Pod undocumented
67 1 my @results;
68 1 foreach my $row ( @{ $self }) {
69 3 push @results, $cb->($row);
70 }
71 1 ▶ return wantarray ? @results : \@results;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 1 1
72 }
73  
74 sub find {
75 4 ▶ my ($self, $cb) = @_;
Subroutine find: called CC=4 SCAR=13.9
Pod undocumented
76 4 my $result;
77 4 foreach my $row ( @{ $self }) {
78 14 my $valid = $cb->({%{$row}});
79 14 ▶ do { $result = $row } and last if $valid;
Branch: 1 branch
BranchTrueFalseTotal
if $valid 3 11 14
Condition75%3/4
$valid && (do { $result = $row } && (last))
!ll
113
do { $result = $row } and last
!ll
03
MC/DC0%0/2
$valid && (do { $result = $row } && (last))
$valid do { $result = $row }
Truth table33%1/3
A && B
A= $validB= do { $result = $row }
ABresult
0X0
100
111
80 }
81 4 return $result;
82 }
83  
84 sub find_index {
85 3 ▶ my ($self, $cb) = @_;
Subroutine find_index: called CC=3 SCAR=11.0
Pod undocumented
86 3 my $i;
87 3 my @rows = @{ $self };
88 3 ▶ for ($i = 0; $i < scalar @rows; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @rows) 10 0 10
89 10 my $row = $rows[$i];
90 10 my $valid = $cb->({%{$row}});
91 10 ▶ last if $valid;
Branch: 1 branch
BranchTrueFalseTotal
if $valid 3 7 10
92 }
93 3 return $i;
94 }
95  
96 sub reverse {
97 2 ▶ my $self = shift;
Subroutine reverse: called CC=1 SCAR=0.0
Pod undocumented
98 2 @{$self} = reverse @{$self};
99 2 return [@{$self}];
100 }
101  
102 sub filter {
103 2 ▶ my ($self, $cb) = @_;
Subroutine filter: called CC=3 SCAR=11.0
Pod undocumented
104 my @results = grep {
105 4 ▶ $cb->({%{$_}}) && $_
Branch: 1 branch
BranchTrueFalseTotal
&$cb({%{$_;}}) and $_ 2 2 4
106 2 } @{ $self };
107 2 ▶ return wantarray ? @results : \@results;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 1 2
108 }
109  
110 sub sort {
111 0 ▶ my ($self, $cb) = @_;
Subroutine sort: not called CC=1 SCAR=6.9
Pod undocumented
112 0 @{ $self } = sort { $cb->($_) } @{ $self };
113 0 @{ $self };
114 }
115  
116 sub shift {
117 0 ▶ shift @{ $_[0] };
Subroutine shift: not called CC=1 SCAR=6.9
Pod undocumented
118 }
119  
120 sub pop {
121 0 ▶ pop @{ $_[0] };
Subroutine pop: not called CC=1 SCAR=6.9
Pod undocumented
122 }
123  
124 sub splice {
125 2 ▶ my ($self, @params) = @_;
Subroutine splice: called CC=1 SCAR=0.0
Pod undocumented
126 2 return splice @{$self}, shift @params, shift @params;
127 }
128  
129 1 1;
« ODS/Table/Column/Base.pm ↑ Summary ODS/Table/Row.pm »