line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DBIx::Otogiri::Iterator; |
2
|
10
|
|
|
10
|
|
63
|
use strict; |
|
10
|
|
|
|
|
21
|
|
|
10
|
|
|
|
|
243
|
|
3
|
10
|
|
|
10
|
|
45
|
use warnings; |
|
10
|
|
|
|
|
18
|
|
|
10
|
|
|
|
|
341
|
|
4
|
|
|
|
|
|
|
use Class::Accessor::Lite ( |
5
|
10
|
|
|
|
|
88
|
new => 0, |
6
|
|
|
|
|
|
|
ro => [qw/db sql binds table/], |
7
|
|
|
|
|
|
|
rw => [qw/sth fetched_count/], |
8
|
10
|
|
|
10
|
|
49
|
); |
|
10
|
|
|
|
|
26
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
11
|
2
|
|
|
2
|
0
|
12
|
my ($class, %opts) = @_; |
12
|
2
|
|
|
|
|
10
|
$opts{sth} = $opts{db}->dbh->prepare($opts{sql}); |
13
|
2
|
50
|
|
|
|
328
|
$opts{sth}->execute($opts{binds} ? @{$opts{binds}} : ()); |
|
2
|
|
|
|
|
36
|
|
14
|
2
|
|
|
|
|
6
|
$opts{fetched_count} = 0; |
15
|
2
|
|
|
|
|
18
|
bless {%opts}, $class; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub next { |
19
|
6
|
|
|
6
|
1
|
5217
|
my $self = shift; |
20
|
6
|
|
|
|
|
23
|
my $row = $self->sth->fetchrow_hashref; |
21
|
6
|
100
|
|
|
|
181
|
unless ($row) { |
22
|
2
|
|
|
|
|
10
|
$self->sth->finish; |
23
|
2
|
|
|
|
|
18
|
$self->{sth} = undef; |
24
|
2
|
|
|
|
|
43
|
return; |
25
|
|
|
|
|
|
|
} |
26
|
4
|
|
|
|
|
12
|
$self->{fetched_count}++; |
27
|
4
|
|
|
|
|
28
|
($row) = $self->db->_inflate_rows($self->table, $row); |
28
|
4
|
|
|
|
|
12
|
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
|
|
|
|
|
|
|
|