Commit | Line | Data |
5cf243f6 |
1 | package DBIx::Class::Cursor; |
1923c0b4 |
2 | |
3 | use strict; |
4 | use warnings; |
1923c0b4 |
5 | |
48a76fcf |
6 | use base qw/DBIx::Class/; |
7 | |
5cf243f6 |
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 | |
5cf243f6 |
33 | Virtual method. Returns a new L<DBIx::Class::Cursor> object. |
34 | |
35 | =cut |
36 | |
1923c0b4 |
37 | sub new { |
28927b50 |
38 | die "Virtual method!"; |
1923c0b4 |
39 | } |
40 | |
5cf243f6 |
41 | =head2 next |
42 | |
685dad64 |
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). |
5cf243f6 |
45 | |
46 | =cut |
47 | |
1923c0b4 |
48 | sub next { |
28927b50 |
49 | die "Virtual method!"; |
1923c0b4 |
50 | } |
51 | |
5cf243f6 |
52 | =head2 reset |
53 | |
5cf243f6 |
54 | Virtual method. Resets the cursor to the beginning. |
55 | |
56 | =cut |
57 | |
1923c0b4 |
58 | sub reset { |
28927b50 |
59 | die "Virtual method!"; |
1909f72b |
60 | } |
61 | |
5cf243f6 |
62 | =head2 all |
63 | |
8e23eaf2 |
64 | Virtual method. Returns all rows in the L<DBIx::Class::ResultSet>. |
5cf243f6 |
65 | |
66 | =cut |
67 | |
1a14aa3f |
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 | |
1923c0b4 |
79 | 1; |