ODS/Iterator.pm

filter: Statementstmt 85.5% 77 / 90 Branchbran 83.3% 15 / 18 Conditioncond 50.0% 6 / 12 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 84.2% 16 / 19 Podpod 0.0% 0 / 16 totaltotal 70.8% 114 / 161 CC 18 SCAR 10.6
CC
18
Cov
82%
flat
6.0
prev
4.5
find
4.0
CRAP 2.9
« ODS/Storage/File.pm ↑ Summary ODS/Table/Row.pm »
1 package ODS::Iterator;
2  
3 72 ▶use YAOO;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 72 auto_build;
6  
7 72 has table => isa(object);
8  
9 72 has next_index => isa(integer(0));
10  
11 72 has prev_index => isa(integer(0));
12  
13 use overload
14 72 ▶ '@{}' => 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 120 ▶ return $_[0]->table->rows;
Subroutine all: called CC=1 SCAR=0.0
Pod undocumented
21 }
22  
23 sub first {
24 4 ▶ return $_[0]->table->rows->[0];
Subroutine first: called CC=1 SCAR=0.0
Pod undocumented
25 }
26  
27 sub last {
28 4 ▶ return $_[0]->table->rows->[-1];
Subroutine last: called CC=1 SCAR=0.0
Pod undocumented
29 }
30  
31 sub next {
32 16 ▶ my $next = $_[0]->table->rows->[$_[0]->next_index];
Subroutine next: called CC=3 SCAR=11.1
Pod undocumented
33 16 $_[0]->next_index($_[0]->next_index + 1);
34 16 ▶ return $next ? $next : $_[0]->next_index(0) && 0;
Branch: 1 branch
BranchTrueFalseTotal
$next ? : 12 4 16
Condition50%1/2
$_[0]->next_index(0) and 0
!ll
40
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 16 ▶ 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 16 16
39 0 $_[0]->prev_index(scalar @{ $_[0] });
40 }
41 16 my $prev = $_[0]->table->rows->[$_[0]->prev_index];
42 16 $_[0]->prev_index($_[0]->prev_index + 1);
43 16 ▶ return $prev ? $prev : $_[0]->prev_index(scalar @{$_[0]}) && 0;
Branch: 1 branch
BranchTrueFalseTotal
$prev ? : 12 4 16
Condition50%1/2
$_[0]->prev_index(scalar @{$_[0];}) and 0
!ll
04
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 3 ▶ my ($self, $keyfield) = @_;
Subroutine array_to_hash: called CC=3 SCAR=11.2
Pod undocumented
57 3 ▶ $keyfield ||= $self->table->keyfield;
Condition33%1/3
$keyfield ||= $self->table->keyfield
l!l&&r!l&&!r
030
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 3 my %hash;
59 3 for my $row (@{ $self }) {
60 9 $hash{$row->{$keyfield}} = {%{$row}};
61 }
62 3 return \%hash;
63 }
64  
65 sub foreach {
66 3 ▶ my ($self, $cb) = @_;
Subroutine foreach: called CC=3 SCAR=11.0
Pod undocumented
67 3 my @results;
68 3 foreach my $row ( @{ $self }) {
69 9 push @results, $cb->($row);
70 }
71 3 ▶ return wantarray ? @results : \@results;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 3 3
72 }
73  
74 sub find {
75 11 ▶ my ($self, $cb) = @_;
Subroutine find: called CC=4 SCAR=13.9
Pod undocumented
76 11 my $result;
77 11 foreach my $row ( @{ $self }) {
78 33 my $valid = $cb->({%{$row}});
79 33 ▶ do { $result = $row } and last if $valid;
Branch: 1 branch
BranchTrueFalseTotal
if $valid 9 24 33
Condition60%3/5
$valid && (do { $result = $row } && (last))
!ll
2490
do { $result = $row } and last
!ll
09
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 11 return $result;
82 }
83  
84 sub find_index {
85 8 ▶ my ($self, $cb) = @_;
Subroutine find_index: called CC=3 SCAR=11.0
Pod undocumented
86 8 my $i;
87 8 my @rows = @{ $self };
88 8 ▶ for ($i = 0; $i < scalar @rows; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @rows) 24 0 24
89 24 my $row = $rows[$i];
90 24 my $valid = $cb->({%{$row}});
91 24 ▶ last if $valid;
Branch: 1 branch
BranchTrueFalseTotal
if $valid 8 16 24
92 }
93 8 return $i;
94 }
95  
96 sub reverse {
97 6 ▶ my $self = shift;
Subroutine reverse: called CC=1 SCAR=0.0
Pod undocumented
98 6 @{$self} = reverse @{$self};
99 6 return [@{$self}];
100 }
101  
102 sub filter {
103 6 ▶ my ($self, $cb) = @_;
Subroutine filter: called CC=3 SCAR=11.0
Pod undocumented
104 my @results = grep {
105 12 ▶ $cb->({%{$_}}) && $_
Branch: 1 branch
BranchTrueFalseTotal
&$cb({%{$_;}}) and $_ 6 6 12
106 6 } @{ $self };
107 6 ▶ return wantarray ? @results : \@results;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 3 3 6
108 }
109  
110 sub sort {
111 1 ▶ my ($self, $cb) = @_;
Subroutine sort: called CC=1 SCAR=0.0
Pod undocumented
112 1 @{ $self } = sort { $cb->($a, $b) } @{ $self };
113 1 $self;
114 }
115  
116 sub shift {
117 0 ▶ CORE::shift @{ $_[0] };
Subroutine shift: not called CC=1 SCAR=6.9
Pod undocumented
118 }
119  
120 sub pop {
121 0 ▶ CORE::pop @{ $_[0] };
Subroutine pop: not called CC=1 SCAR=6.9
Pod undocumented
122 }
123  
124 sub splice {
125 5 ▶ my ($self, @params) = @_;
Subroutine splice: called CC=1 SCAR=0.0
Pod undocumented
126  
127 5 return splice( @{$self}, CORE::shift @params, CORE::shift @params);
128 }
129  
130 72 1;
« ODS/Storage/File.pm ↑ Summary ODS/Table/Row.pm »