Bulk/DBI.pm

filter: Statementstmt 71.4% 15 / 21 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 60.0% 3 / 5 Podpod 100% 2 / 2 totaltotal 71.4% 20 / 28 CC 1 SCAR 3.4
CC
1
Cov
71%
get_more
2.0
all
2.0
BEGIN
1.0
CRAP 1.4
« Bulk/DoneFlag.pm ↑ Summary Bulk/Util.pm »
1 package Data::Stream::Bulk::DBI;
2 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 $Data::Stream::Bulk::DBI::AUTHORITY = 'cpan:NUFFIN';
4 }
5 {
6 1 $Data::Stream::Bulk::DBI::VERSION = '0.11';
7 }
8 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 # ABSTRACT: N-at-a-time iteration of L<DBI> statement results.
10  
11 1 ▶use namespace::clean -except => 'meta';
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 with qw(Data::Stream::Bulk::DoneFlag) => { -excludes => [qw/is_done all finished/] };
14  
15 1 has sth => (
16 isa => "Object",
17 is => "ro",
18 required => 1,
19 handles => [qw(fetchall_arrayref)],
20 clearer => "finished",
21 );
22  
23 1 has slice => (
24 is => "ro",
25 );
26  
27 1 has max_rows => (
28 isa => "Int",
29 is => "rw",
30 default => 500,
31 );
32  
33 0 ▶sub get_more {
Subroutine get_more: not called CC=1 SCAR=6.9
Pod documented
34 0 my $self = shift;
35 0 $self->fetchall_arrayref( $self->slice, $self->max_rows );
36 }
37  
38 0 ▶sub all {
Subroutine all: not called CC=1 SCAR=6.9
Pod documented
39 0 my $self = shift;
40  
41 0 my $all = $self->fetchall_arrayref( $self->slice );
42  
43 0 $self->_set_done;
44  
45 0 return @$all;
46 }
47  
48 1 __PACKAGE__->meta->make_immutable;
49  
50 1 __PACKAGE__;
51  
52  
53  
54 =pod
55  
56 =head1 NAME
57  
58 Data::Stream::Bulk::DBI - N-at-a-time iteration of L<DBI> statement results.
59  
60 =head1 VERSION
61  
62 version 0.11
63  
64 =head1 SYNOPSIS
65  
66 use Data::Stream::Bulk::DBI;
67  
68 my $sth = $dbh->prepare("SELECT hate FROM sql"); # very big resultset
69 $sth->execute;
70  
71 return Data::Stream::Bulk::DBI->new(
72 sth => $sth,
73 max_rows => $n, # how many at a time
74 slice => [ ... ], # if you want to pass the first param to fetchall_arrayref
75 );
76  
77 =head1 DESCRIPTION
78  
79 This implementation of L<Data::Stream::Bulk> api works with DBI statement
80 handles, using L<DBI/fetchall_arrayref>.
81  
82 It fetches C<max_rows> at a time (defaults to 500).
83  
84 =head1 ATTRIBUTES
85  
86 =over 4
87  
88 =item sth
89  
90 The statement handle to call C<fetchall_arrayref> on.
91  
92 =item slice
93  
94 Passed verbatim as the first param to C<fetchall_arrayref>. Should usually be
95 C<undef>, provided for completetness.
96  
97 =item max_rows
98  
99 The second param to C<fetchall_arrayref>. Controls the size of each buffer.
100  
101 Defaults to 500.
102  
103 =back
104  
105 =head1 METHODS
106  
107 =over 4
108  
109 =item get_more
110  
111 See L<Data::Stream::Bulk::DoneFlag>.
112  
113 Calls C<fetchall_arrayref> to get the next chunk of rows.
114  
115 =item all
116  
117 Calls C<fetchall_arrayref> to get the raminder of the data (without specifying
118 C<max_rows>).
119  
120 =back
121  
122 =head1 AUTHOR
123  
124 Yuval Kogman <nothingmuch@woobling.org>
125  
126 =head1 COPYRIGHT AND LICENSE
127  
128 This software is copyright (c) 2012 by Yuval Kogman.
129  
130 This is free software; you can redistribute it and/or modify it under
131 the same terms as the Perl 5 programming language system itself.
132  
133 =cut
134  
135  
136 __END__
« Bulk/DoneFlag.pm ↑ Summary Bulk/Util.pm »