Update to add myself to contributors and to hide Modules from the PAUSE Indexer.
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage / DBI / Cursor.pm
1 package # hide from PAUSE 
2     DBIx::Class::Storage::DBI::Cursor;
3
4 use base qw/DBIx::Class::Cursor/;
5
6 use strict;
7 use warnings;
8
9 sub new {
10   my ($class, $storage, $args, $attrs) = @_;
11   #use Data::Dumper; warn Dumper(@_);
12   $class = ref $class if ref $class;
13   my $new = {
14     storage => $storage,
15     args => $args,
16     pos => 0,
17     attrs => $attrs };
18   return bless ($new, $class);
19 }
20
21 sub next {
22   my ($self) = @_;
23   if ($self->{attrs}{rows} && $self->{pos} >= $self->{attrs}{rows}) {
24     $self->{sth}->finish if $self->{sth}->{Active};
25     delete $self->{sth};
26     $self->{done} = 1;
27   }
28   return if $self->{done};
29   unless ($self->{sth}) {
30     $self->{sth} = ($self->{storage}->_select(@{$self->{args}}))[1];
31     if ($self->{attrs}{software_limit}) {
32       if (my $offset = $self->{attrs}{offset}) {
33         $self->{sth}->fetch for 1 .. $offset;
34       }
35     }
36   }
37   my @row = $self->{sth}->fetchrow_array;
38   if (@row) {
39     $self->{pos}++;
40   } else {
41     delete $self->{sth};
42     $self->{done} = 1;
43   }
44   return @row;
45 }
46
47 sub all {
48   my ($self) = @_;
49   return $self->SUPER::all if $self->{attrs}{rows};
50   $self->{sth}->finish if $self->{sth}->{Active};
51   delete $self->{sth};
52   my ($rv, $sth) = $self->{storage}->_select(@{$self->{args}});
53   return @{$sth->fetchall_arrayref};
54 }
55
56 sub reset {
57   my ($self) = @_;
58   $self->{sth}->finish if $self->{sth}->{Active};
59   delete $self->{sth};
60   $self->{pos} = 0;
61   delete $self->{done};
62   return $self;
63 }
64
65 sub DESTROY {
66   my ($self) = @_;
67   $self->{sth}->finish if $self->{sth}->{Active};
68 }
69
70 1;