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