1Class::DBI::Iterator(3)User Contributed Perl DocumentatioCnlass::DBI::Iterator(3)
2
3
4
6 Class::DBI::Iterator - Iterate over Class::DBI search results
7
9 my $it = My::Class->search(foo => 'bar');
10
11 my $results = $it->count;
12
13 my $first_result = $it->first;
14 while ($it->next) { ... }
15
16 my @slice = $it->slice(10,19);
17 my $slice = $it->slice(10,19);
18
19 $it->reset;
20
21 $it->delete_all;
22
24 Any Class::DBI search (including a has_many method) which returns
25 multiple objects can be made to return an iterator instead simply by
26 executing the search in scalar context.
27
28 Then, rather than having to fetch all the results at the same time, you
29 can fetch them one at a time, potentially saving a considerable amount
30 of processing time and memory.
31
33 Note that there is no provision for the data changing (or even being
34 deleted) in the database inbetween performing the search and retrieving
35 the next result.
36
37
38
39perl v5.34.0 2022-01-21 Class::DBI::Iterator(3)