Bug 22770: DBRev 19.05.00.003
[koha.git] / Koha / MetadataIterator.pm
1 package Koha::MetadataIterator;
2
3 # This contains an iterator over biblio and authority records
4
5 # Copyright 2014 Catalyst IT
6 #
7 # This file is part of Koha.
8 #
9 # Koha is free software; you can redistribute it and/or modify it under the
10 # terms of the GNU General Public License as published by the Free Software
11 # Foundation; either version 3 of the License, or (at your option) any later
12 # version.
13 #
14 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
15 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License along
19 # with Koha; if not, write to the Free Software Foundation, Inc.,
20 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
22 =head1 NAME
23
24 Koha::MetadataIterator - iterates over records
25
26 =head1 DESCRIPTION
27
28 This provides a fairly generic iterator that will return records provided
29 by a function.
30
31 =head1 SYNOPSIS
32
33     use Koha::MetadataIterator;
34     my $next_func = sub {
35         # something that'll return each record
36     };
37     my $iterator = Koha::MetadataIterator->new($next_func);
38     while ( my $record = $iterator->next() ) {
39         # do something with $record
40     }
41
42 =head1 METHODS
43
44 =cut
45
46 use Modern::Perl;
47
48 =head2 new
49
50     my $it = new($next_func);
51
52 Takes a function that will provide the next bit of data.
53
54 =cut
55
56 sub new {
57     my ( $class, $next_func ) = @_;
58
59     bless { next_func => $next_func, }, $class;
60 }
61
62 =head2 next()
63
64 Provides the next record.
65
66 =cut
67
68 sub next {
69     my ($self) = @_;
70
71     return $self->{next_func}->();
72 }
73
74 1;