line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!perl |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
15
|
use strict; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
90
|
|
4
|
3
|
|
|
3
|
|
15
|
use warnings; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
164
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
package DBIx::Iterator::Statement; |
7
|
|
|
|
|
|
|
{ |
8
|
|
|
|
|
|
|
$DBIx::Iterator::Statement::VERSION = '0.0.2'; |
9
|
|
|
|
|
|
|
} |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# ABSTRACT: Query your database using iterators and save memory |
12
|
|
|
|
|
|
|
|
13
|
3
|
|
|
3
|
|
14
|
use Carp qw(confess); |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
1008
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub new { |
17
|
4
|
|
|
4
|
1
|
9
|
my ($class, $query, $db) = @_; |
18
|
4
|
50
|
|
|
|
21
|
confess("Please specify a database query") unless defined $query; |
19
|
4
|
50
|
|
|
|
13
|
confess("Please specify a database iterator factory") unless defined $db; |
20
|
4
|
|
|
|
|
16
|
my $sth = $db->dbh->prepare($query); |
21
|
4
|
|
|
|
|
14964
|
return bless { |
22
|
|
|
|
|
|
|
'sth' => $sth, |
23
|
|
|
|
|
|
|
'db' => $db, |
24
|
|
|
|
|
|
|
}, $class; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub db { |
29
|
1
|
|
|
1
|
1
|
735
|
my ($self) = @_; |
30
|
1
|
|
|
|
|
10
|
return $self->{'db'}; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub sth { |
35
|
12
|
|
|
12
|
1
|
586
|
my ($self) = @_; |
36
|
12
|
|
|
|
|
138
|
return $self->{'sth'}; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
## no critic (Subroutines::RequireArgUnpacking) |
41
|
|
|
|
|
|
|
sub bind_param { |
42
|
1
|
|
|
1
|
1
|
361
|
my $self = shift; |
43
|
1
|
|
|
|
|
4
|
return $self->sth->bind_param(@_); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
## use critic |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
## no critic (Subroutines::RequireArgUnpacking) |
49
|
|
|
|
|
|
|
sub execute { |
50
|
3
|
|
|
3
|
1
|
584
|
my $self = shift; |
51
|
3
|
|
|
|
|
9
|
$self->sth->execute(@_); |
52
|
|
|
|
|
|
|
## use critic |
53
|
|
|
|
|
|
|
return sub { |
54
|
6
|
|
|
6
|
|
3664
|
my $row = $self->sth->fetchrow_hashref(); |
55
|
6
|
100
|
|
|
|
449
|
return $row, $self if wantarray; |
56
|
2
|
|
|
|
|
8
|
return $row; |
57
|
3
|
|
|
|
|
1118
|
}; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
1; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
__END__ |