|
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 136-149
Returns undef if there are no more objects to return.
Link Here
|
| 136 |
sub next { |
140 |
sub next { |
| 137 |
my ( $self ) = @_; |
141 |
my ( $self ) = @_; |
| 138 |
|
142 |
|
| 139 |
my $result = $self->_resultset()->next(); |
143 |
my $object = $self->_objects()->[ $self->{_iterator}++ ]; |
| 140 |
return unless $result; |
|
|
| 141 |
|
144 |
|
| 142 |
my $object = $self->object_class()->_new_from_dbic( $result ); |
145 |
$self->reset() unless $object; |
| 143 |
|
146 |
|
| 144 |
return $object; |
147 |
return $object; |
| 145 |
} |
148 |
} |
| 146 |
|
149 |
|
|
|
150 |
=head3 Koha::Objects->first(); |
| 151 |
|
| 152 |
my $object = Koha::Objects->first(); |
| 153 |
|
| 154 |
Returns the first object that is part of this set. |
| 155 |
|
| 156 |
=cut |
| 157 |
|
| 158 |
sub first { |
| 159 |
my ( $self ) = @_; |
| 160 |
|
| 161 |
return $self->_objects()->[0]; |
| 162 |
} |
| 163 |
|
| 147 |
=head3 Koha::Objects->reset(); |
164 |
=head3 Koha::Objects->reset(); |
| 148 |
|
165 |
|
| 149 |
Koha::Objects->reset(); |
166 |
Koha::Objects->reset(); |
|
Lines 156-162
with the first object in a set.
Link Here
|
| 156 |
sub reset { |
173 |
sub reset { |
| 157 |
my ( $self ) = @_; |
174 |
my ( $self ) = @_; |
| 158 |
|
175 |
|
| 159 |
$self->_resultset()->reset(); |
176 |
$self->{_iterator} = 0; |
| 160 |
|
177 |
|
| 161 |
return $self; |
178 |
return $self; |
| 162 |
} |
179 |
} |
|
Lines 172-182
Returns an arrayref of the objects in this set.
Link Here
|
| 172 |
sub as_list { |
189 |
sub as_list { |
| 173 |
my ( $self ) = @_; |
190 |
my ( $self ) = @_; |
| 174 |
|
191 |
|
| 175 |
my @dbic_rows = $self->_resultset()->all(); |
192 |
my $objects = $self->_objects(); |
|
|
193 |
|
| 194 |
return wantarray ? @$objects : $objects; |
| 195 |
} |
| 196 |
|
| 197 |
=head3 Koha::Objects->_objects |
| 198 |
|
| 199 |
Returns an arrayref of all the objects that are part of this Objects set |
| 200 |
|
| 201 |
=cut |
| 202 |
|
| 203 |
sub _objects { |
| 204 |
my ( $self ) = @_; |
| 176 |
|
205 |
|
| 177 |
my @objects = $self->_wrap(@dbic_rows); |
206 |
$self->{_objects} ||= $self->_wrap( $self->_resultset()->all() ); |
| 178 |
|
207 |
|
| 179 |
return wantarray ? @objects : \@objects; |
208 |
return $self->{_objects}; |
| 180 |
} |
209 |
} |
| 181 |
|
210 |
|
| 182 |
=head3 Koha::Objects->_wrap |
211 |
=head3 Koha::Objects->_wrap |
|
Lines 190-196
sub _wrap {
Link Here
|
| 190 |
|
219 |
|
| 191 |
my @objects = map { $self->object_class()->_new_from_dbic( $_ ) } @dbic_rows; |
220 |
my @objects = map { $self->object_class()->_new_from_dbic( $_ ) } @dbic_rows; |
| 192 |
|
221 |
|
| 193 |
return @objects; |
222 |
return wantarray ? @objects : \@objects;; |
| 194 |
} |
223 |
} |
| 195 |
|
224 |
|
| 196 |
=head3 Koha::Objects->_resultset |
225 |
=head3 Koha::Objects->_resultset |
| 197 |
- |
|
|