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