lib/IMDB/Local/DB/RecordIterator.pm

filter: Statementstmt 26.0% 13 / 50 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 50.0% 4 / 8 Podpod 100% 3 / 3 totaltotal 26.3% 20 / 76 SCAR 36.9
CC
8
Cov
21%
_cacheRows
20.0
nextRow
20.0
new
6.0
CRAP 40.0
« lib/IMDB/Local/DB.pm ↑ Summary lib/IMDB/Local/Actor.pm »
1 package IMDB::Local::DB::RecordIterator;
2  
3 1 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 =head1 NAME
9  
10 IMDB::Local::DB::RecordIterator - Object to iterate through search results
11  
12 =head1 VERSION
13  
14 Version 0.01
15  
16 =cut
17  
18 1 our $VERSION = '1.00';
19  
20  
21 =head1 SYNOPSIS
22  
23 Quick summary of what the module does.
24  
25 Perhaps a little code snippet.
26  
27 use IMDB::Local::DB::RecordIterator;
28  
29 my $foo = IMDB::Local::DB::RecordIterator->new();
30 ...
31  
32 =head1 EXPORT
33  
34 A list of functions that can be exported. You can delete this section
35 if you don't export anything, such as for a purely object-oriented module.
36  
37 =head1 SUBROUTINES/METHODS
38  
39 =head2 new
40  
41 =cut
42  
43 sub new($$)
44 {
45 0 ▶ my ($class, $sth)=@_;
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
46  
47 0 ▶ if ( !defined($sth) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $sth) 0 0 0
48 0 carp("sth is not defined");
49 0 return(undef);
50 }
51  
52 0 my $self={sth=>$sth};
53  
54 0 $self->{cacheBy}=1000;
55 0 $self->{cacheSize}=0;
56 0 bless($self, $class);
57 0 $self->{rowIntoCache}=0;
58 0 $self->{rowCounter}=0;
59 0 return($self);
60 }
61  
62 sub _cacheRows($)
63 {
64 0 ▶ my $self=shift;
Subroutine _cacheRows: not called CC=4 SCAR=30.0
65  
66 0 delete($self->{cache});
67 0 $self->{cacheSize}=0;
68
69 0 my $all=$self->{sth}->fetchall_arrayref(undef, $self->{cacheBy});
70 0 my @list;
71 0 for my $refer (@$all) {
72 0 my @ref=@$refer;
73 0 ▶ if ( @ref ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@ref) 0 0 0
74 0 push(@list, \@ref);
75 }
76 }
77 0 ▶ if ( @list ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@list) 0 0 0
78 0 $self->{cache}=\@list;
79 0 $self->{cacheSize}=scalar(@list);
80 #print "cached ".$self->{cacheSize}."\n";
81 0 return($self->{cache});
82 }
83 0 return(0);
84 }
85  
86 =head2 nextRow
87  
88 =cut
89  
90 sub nextRow($)
91 {
92 0 ▶ my $self=shift;
Subroutine nextRow: not called CC=4 SCAR=30.0
Pod documented
93  
94 0 ▶ if ( !$self->{cache} || $self->{rowIntoCache}+1 >= $self->{cacheSize} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{'cache'} or $self->{'rowIntoCache'} + 1 >= $self->{'cacheSize'}) { } 0 0 0
Condition0%0/3
not $self->{"cache"} or $self->{"rowIntoCache"} + 1 >= $self->{"cacheSize"}
l!l&&r!l&&!r
000
MC/DC0%0/2
not $self->{"cache"} or $self->{"rowIntoCache"} + 1 >= $self->{"cacheSize"}
not $self->{"cache"} $self->{"rowIntoCache"} + 1 >= $self->{"cacheSize"}
Truth table0%0/3
not(A) or B
A= not $self->{"cache"}B= $self->{"rowIntoCache"} + 1 >= $self->{"cacheSize"}
ABresult
1X1
011
000
95 0 ▶ if ( !$self->_cacheRows() ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_cacheRows) 0 0 0
96 # no more rows
97 0 return(undef);
98 }
99 0 $self->{rowIntoCache}=0;
100 }
101 else {
102 0 $self->{rowIntoCache}++;
103 }
104 0 my @arr=@{$self->{cache}};
105 #print "returning ".$self->{rowIntoCache}." row\n";
106 0 my $refer=$arr[$self->{rowIntoCache}];
107 0 return(\@$refer);
108 }
109  
110 =head2 rowNumber
111  
112 =cut
113  
114 sub rowNumber($)
115 {
116 0 ▶ my $self=shift;
Subroutine rowNumber: not called CC=1 SCAR=6.9
Pod documented
117 0 return($self->{rowCounter});
118 }
119  
120  
121 =head1 AUTHOR
122  
123 jerryv, C<< <jerry.veldhuis at gmail.com> >>
124  
125 =head1 BUGS
126  
127 Please report any bugs or feature requests to C<bug-imdb-local at rt.cpan.org>, or through
128 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=IMDB-Local>. I will be notified, and then you'll
129 automatically be notified of progress on your bug as I make changes.
130  
131  
132  
133  
134 =head1 SUPPORT
135  
136 You can find documentation for this module with the perldoc command.
137  
138 perldoc IMDB::Local::DB::RecordIterator
139  
140  
141 You can also look for information at:
142  
143 =over 4
144  
145 =item * RT: CPAN's request tracker (report bugs here)
146  
147 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=IMDB-Local>
148  
149 =item * AnnoCPAN: Annotated CPAN documentation
150  
151 L<http://annocpan.org/dist/IMDB-Local>
152  
153 =item * CPAN Ratings
154  
155 L<http://cpanratings.perl.org/d/IMDB-Local>
156  
157 =item * Search CPAN
158  
159 L<http://search.cpan.org/dist/IMDB-Local/>
160  
161 =back
162  
163  
164 =head1 ACKNOWLEDGEMENTS
165  
166  
167 =head1 LICENSE AND COPYRIGHT
168  
169 Copyright 2015 jerryv.
170  
171 This program is free software; you can redistribute it and/or modify it
172 under the terms of the the Artistic License (2.0). You may obtain a
173 copy of the full license at:
174  
175 L<http://www.perlfoundation.org/artistic_license_2_0>
176  
177 Any use, modification, and distribution of the Standard or Modified
178 Versions is governed by this Artistic License. By using, modifying or
179 distributing the Package, you accept this license. Do not use, modify,
180 or distribute the Package, if you do not accept this license.
181  
182 If your Modified Version has been derived from a Modified Version made
183 by someone other than you, you are nevertheless required to ensure that
184 your Modified Version complies with the requirements of this license.
185  
186 This license does not grant you the right to use any trademark, service
187 mark, tradename, or logo of the Copyright Holder.
188  
189 This license includes the non-exclusive, worldwide, free-of-charge
190 patent license to make, have made, use, offer to sell, sell, import and
191 otherwise transfer the Package with respect to any patent claims
192 licensable by the Copyright Holder that are necessarily infringed by the
193 Package. If you institute patent litigation (including a cross-claim or
194 counterclaim) against any party alleging that the Package constitutes
195 direct or contributory patent infringement, then this Artistic License
196 to you shall terminate on the date that such litigation is filed.
197  
198 Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER
199 AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
200 THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
201 PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY
202 YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
203 CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR
204 CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE,
205 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
206  
207  
208 =cut
209  
210 1 1; # End of IMDB::Local::DB::RecordIterator
« lib/IMDB/Local/DB.pm ↑ Summary lib/IMDB/Local/Actor.pm »