Lines 54-59
sub new {
Link Here
|
54 |
my ($class) = @_; |
54 |
my ($class) = @_; |
55 |
my $self = {}; |
55 |
my $self = {}; |
56 |
|
56 |
|
|
|
57 |
$self->{_iterator} = 0; |
58 |
|
57 |
bless( $self, $class ); |
59 |
bless( $self, $class ); |
58 |
} |
60 |
} |
59 |
|
61 |
|
Lines 67-72
sub _new_from_dbic {
Link Here
|
67 |
my ( $class, $resultset ) = @_; |
69 |
my ( $class, $resultset ) = @_; |
68 |
my $self = { _resultset => $resultset }; |
70 |
my $self = { _resultset => $resultset }; |
69 |
|
71 |
|
|
|
72 |
$self->{_iterator} = 0; |
73 |
|
70 |
bless( $self, $class ); |
74 |
bless( $self, $class ); |
71 |
} |
75 |
} |
72 |
|
76 |
|
Lines 138-147
Returns undef if there are no more objects to return.
Link Here
|
138 |
sub next { |
142 |
sub next { |
139 |
my ( $self ) = @_; |
143 |
my ( $self ) = @_; |
140 |
|
144 |
|
141 |
my $result = $self->_resultset()->next(); |
145 |
my $object = $self->_objects()->[ $self->{_iterator}++ ]; |
142 |
return unless $result; |
|
|
143 |
|
146 |
|
144 |
my $object = $self->object_class()->_new_from_dbic( $result ); |
147 |
$self->reset() unless $object; |
145 |
|
148 |
|
146 |
return $object; |
149 |
return $object; |
147 |
} |
150 |
} |
Lines 157-168
Returns the first object that is part of this set.
Link Here
|
157 |
sub first { |
160 |
sub first { |
158 |
my ( $self ) = @_; |
161 |
my ( $self ) = @_; |
159 |
|
162 |
|
160 |
my $result = $self->_resultset()->first(); |
163 |
return $self->_objects()->[0]; |
161 |
return unless $result; |
|
|
162 |
|
163 |
my $object = $self->object_class()->_new_from_dbic( $result ); |
164 |
|
165 |
return $object; |
166 |
} |
164 |
} |
167 |
|
165 |
|
168 |
=head3 Koha::Objects->reset(); |
166 |
=head3 Koha::Objects->reset(); |
Lines 177-183
with the first object in a set.
Link Here
|
177 |
sub reset { |
175 |
sub reset { |
178 |
my ( $self ) = @_; |
176 |
my ( $self ) = @_; |
179 |
|
177 |
|
180 |
$self->_resultset()->reset(); |
178 |
$self->{_iterator} = 0; |
181 |
|
179 |
|
182 |
return $self; |
180 |
return $self; |
183 |
} |
181 |
} |
Lines 193-203
Returns an arrayref of the objects in this set.
Link Here
|
193 |
sub as_list { |
191 |
sub as_list { |
194 |
my ( $self ) = @_; |
192 |
my ( $self ) = @_; |
195 |
|
193 |
|
196 |
my @dbic_rows = $self->_resultset()->all(); |
194 |
my $objects = $self->_objects(); |
|
|
195 |
|
196 |
return wantarray ? @$objects : $objects; |
197 |
} |
198 |
|
199 |
=head3 Koha::Objects->_objects |
200 |
|
201 |
Returns an arrayref of all the objects that are part of this Objects set |
202 |
|
203 |
=cut |
204 |
|
205 |
sub _objects { |
206 |
my ( $self ) = @_; |
197 |
|
207 |
|
198 |
my @objects = $self->_wrap(@dbic_rows); |
208 |
$self->{_objects} ||= $self->_wrap( $self->_resultset()->all() ); |
199 |
|
209 |
|
200 |
return wantarray ? @objects : \@objects; |
210 |
return $self->{_objects}; |
201 |
} |
211 |
} |
202 |
|
212 |
|
203 |
=head3 Koha::Objects->_wrap |
213 |
=head3 Koha::Objects->_wrap |
Lines 211-217
sub _wrap {
Link Here
|
211 |
|
221 |
|
212 |
my @objects = map { $self->object_class()->_new_from_dbic( $_ ) } @dbic_rows; |
222 |
my @objects = map { $self->object_class()->_new_from_dbic( $_ ) } @dbic_rows; |
213 |
|
223 |
|
214 |
return @objects; |
224 |
return wantarray ? @objects : \@objects;; |
215 |
} |
225 |
} |
216 |
|
226 |
|
217 |
=head3 Koha::Objects->_resultset |
227 |
=head3 Koha::Objects->_resultset |
218 |
- |
|
|