fix and regression test for RT #62642
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Cursor.pm
1 package DBIx::Class::Cursor;
2
3 use strict;
4 use warnings;
5
6 use base qw/DBIx::Class/;
7
8 =head1 NAME
9
10 DBIx::Class::Cursor - Abstract object representing a query cursor on a
11 resultset.
12
13 =head1 SYNOPSIS
14
15   my $cursor = $schema->resultset('CD')->cursor();
16   my $first_cd = $cursor->next;
17
18 =head1 DESCRIPTION
19
20 A Cursor represents a query cursor on a L<DBIx::Class::ResultSet> object. It
21 allows for traversing the result set with L</next>, retrieving all results with
22 L</all> and resetting the cursor with L</reset>.
23
24 Usually, you would use the cursor methods built into L<DBIx::Class::ResultSet>
25 to traverse it. See L<DBIx::Class::ResultSet/next>,
26 L<DBIx::Class::ResultSet/reset> and L<DBIx::Class::ResultSet/all> for more
27 information.
28
29 =head1 METHODS
30
31 =head2 new
32
33 Virtual method. Returns a new L<DBIx::Class::Cursor> object.
34
35 =cut
36
37 sub new {
38   die "Virtual method!";
39 }
40
41 =head2 next
42
43 Virtual method. Advances the cursor to the next row. Returns an array of
44 column values (the result of L<DBI/fetchrow_array> method).
45
46 =cut
47
48 sub next {
49   die "Virtual method!";
50 }
51
52 =head2 reset
53
54 Virtual method. Resets the cursor to the beginning.
55
56 =cut
57
58 sub reset {
59   die "Virtual method!";
60 }
61
62 =head2 all
63
64 Virtual method. Returns all rows in the L<DBIx::Class::ResultSet>.
65
66 =cut
67
68 sub all {
69   my ($self) = @_;
70   $self->reset;
71   my @all;
72   while (my @row = $self->next) {
73     push(@all, \@row);
74   }
75   $self->reset;
76   return @all;
77 }
78
79 1;