87b0267102bccf5f9fe7e277cd5326a96cb0afff
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage / DBI / Cursor.pm
1 package DBIx::Class::Storage::DBI::Cursor;
2
3 use base qw/DBIx::Class::Cursor/;
4
5 use strict;
6 use warnings;
7
8 sub new {
9   my ($it_class, $sth, $args, $attrs) = @_;
10   #use Data::Dumper; warn Dumper(@_);
11   $it_class = ref $it_class if ref $it_class;
12   my $new = {
13     sth => $sth,
14     args => $args,
15     pos => 0,
16     attrs => $attrs };
17   return bless ($new, $it_class);
18 }
19
20 sub next {
21   my ($self) = @_;
22   return if $self->{attrs}{rows}
23     && $self->{pos} >= $self->{attrs}{rows}; # + $self->{attrs}{offset});
24   unless ($self->{live_sth}) {
25     $self->{sth}->execute(@{$self->{args} || []});
26     if (my $offset = $self->{attrs}{offset}) {
27       $self->{sth}->fetch for 1 .. $offset;
28     }
29     $self->{live_sth} = 1;
30   }
31   my @row = $self->{sth}->fetchrow_array;
32   $self->{pos}++ if @row;
33   return @row;
34 }
35
36 sub reset {
37   my ($self) = @_;
38   $self->{sth}->finish if $self->{sth}->{Active};
39   $self->{pos} = 0;
40   $self->{live_sth} = 0;
41   return $self;
42 }
43
44 sub DESTROY {
45   my ($self) = @_;
46   $self->{sth}->finish if $self->{sth}->{Active};
47 }
48
49 1;