Refactoring, cleanup, lose unnecessary resultset/cursor objects
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage / DBI / Cursor.pm
CommitLineData
28927b50 1package DBIx::Class::Storage::DBI::Cursor;
2
3use base qw/DBIx::Class::Cursor/;
4
5use strict;
6use warnings;
7
8sub 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
20sub next {
21 my ($self) = @_;
22 return if $self->{attrs}{rows}
23 && $self->{pos} >= $self->{attrs}{rows}; # + $self->{attrs}{offset});
1a14aa3f 24 my $sth = $self->{sth};
28927b50 25 unless ($self->{live_sth}) {
1a14aa3f 26 $sth->execute(@{$self->{args} || []});
28927b50 27 if (my $offset = $self->{attrs}{offset}) {
1a14aa3f 28 $sth->fetch for 1 .. $offset;
28927b50 29 }
30 $self->{live_sth} = 1;
31 }
1a14aa3f 32 my @row = $sth->fetchrow_array;
28927b50 33 $self->{pos}++ if @row;
34 return @row;
35}
36
1a14aa3f 37sub all {
38 my ($self) = @_;
39 return $self->SUPER::all if $self->{attrs}{rows};
40 my $sth = $self->{sth};
41 $sth->finish if $sth->{Active};
42 $sth->execute(@{$self->{args} || []});
43 delete $self->{live_sth};
44 return @{$sth->fetchall_arrayref};
45}
46
28927b50 47sub reset {
48 my ($self) = @_;
49 $self->{sth}->finish if $self->{sth}->{Active};
50 $self->{pos} = 0;
51 $self->{live_sth} = 0;
52 return $self;
53}
54
55sub DESTROY {
56 my ($self) = @_;
57 $self->{sth}->finish if $self->{sth}->{Active};
58}
59
601;