| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package DBIx::Otogiri::Iterator; |
|
2
|
10
|
|
|
10
|
|
73
|
use strict; |
|
|
10
|
|
|
|
|
20
|
|
|
|
10
|
|
|
|
|
296
|
|
|
3
|
10
|
|
|
10
|
|
53
|
use warnings; |
|
|
10
|
|
|
|
|
26
|
|
|
|
10
|
|
|
|
|
419
|
|
|
4
|
|
|
|
|
|
|
use Class::Accessor::Lite ( |
|
5
|
10
|
|
|
|
|
96
|
new => 0, |
|
6
|
|
|
|
|
|
|
ro => [qw/db sql binds table/], |
|
7
|
|
|
|
|
|
|
rw => [qw/sth fetched_count/], |
|
8
|
10
|
|
|
10
|
|
76
|
); |
|
|
10
|
|
|
|
|
25
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
|
11
|
2
|
|
|
2
|
0
|
13
|
my ($class, %opts) = @_; |
|
12
|
2
|
|
|
|
|
9
|
$opts{sth} = $opts{db}->dbh->prepare($opts{sql}); |
|
13
|
2
|
50
|
|
|
|
313
|
$opts{sth}->execute($opts{binds} ? @{$opts{binds}} : ()); |
|
|
2
|
|
|
|
|
28
|
|
|
14
|
2
|
|
|
|
|
7
|
$opts{fetched_count} = 0; |
|
15
|
2
|
|
|
|
|
33
|
bless {%opts}, $class; |
|
16
|
|
|
|
|
|
|
} |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub next { |
|
19
|
6
|
|
|
6
|
1
|
5830
|
my $self = shift; |
|
20
|
6
|
|
|
|
|
20
|
my $row = $self->sth->fetchrow_hashref; |
|
21
|
6
|
100
|
|
|
|
170
|
unless ($row) { |
|
22
|
2
|
|
|
|
|
8
|
$self->sth->finish; |
|
23
|
2
|
|
|
|
|
43
|
$self->{sth} = undef; |
|
24
|
2
|
|
|
|
|
8
|
return; |
|
25
|
|
|
|
|
|
|
} |
|
26
|
4
|
|
|
|
|
8
|
$self->{fetched_count}++; |
|
27
|
4
|
|
|
|
|
16
|
($row) = $self->db->_inflate_rows($self->table, $row); |
|
28
|
4
|
|
|
|
|
16
|
return $row; |
|
29
|
|
|
|
|
|
|
} |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
1; |
|
32
|
|
|
|
|
|
|
__END__ |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=encoding utf-8 |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head1 NAME |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
DBIx::Otogiri::Iterator - Iterator class for Otogiri |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
use Otogiri; |
|
43
|
|
|
|
|
|
|
my $db = Otogiri->new(connect_info => ['dbi:SQLite:...', '', '']); |
|
44
|
|
|
|
|
|
|
my $iter = $db->select(book => {price => {'>=' => 500}}); |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
while (my $row = $iter->next) { |
|
47
|
|
|
|
|
|
|
printf "Title: %s \nPrice: %s yen\n", $row->{title}, $row->{price}; |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
printf "rows = %s\n", $iter->fetched_count; |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
Iterator class for Otogiri. DO NOT USE THIS CLASS DIRECTLY. |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head1 METHODS |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head2 next |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
my $row = $iter->next; |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
Returns a row data as single hashref. Then, increment internal value "fetched_count". |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head2 fetched_count |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
my $count = $iter->fetched_count; |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
Returns a current "fetched_count". |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head1 LICENSE |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
Copyright (C) ytnobody. |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
|
75
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head1 AUTHOR |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
ytnobody E<lt>ytnobody@gmail.comE<gt> |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
L<DBIx::Otogiri> |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=cut |
|
86
|
|
|
|
|
|
|
|