View | Details | Raw Unified | Return to bug 13019
Collapse All | Expand All

(-)a/Koha/Objects.pm (-18 / +23 lines)
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-149 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
    return $self->_objects()->[ $self->{_iterator}++ ];
142
    return unless $result;
143
144
    my $object = $self->object_class()->_new_from_dbic( $result );
145
146
    return $object;
147
}
146
}
148
147
149
=head3 Koha::Objects->first();
148
=head3 Koha::Objects->first();
Lines 157-168 Returns the first object that is part of this set. Link Here
157
sub first {
156
sub first {
158
    my ( $self ) = @_;
157
    my ( $self ) = @_;
159
158
160
    my $result = $self->_resultset()->first();
159
    return $self->_objects()->[0];
161
    return unless $result;
162
163
    my $object = $self->object_class()->_new_from_dbic( $result );
164
165
    return $object;
166
}
160
}
167
161
168
=head3 Koha::Objects->reset();
162
=head3 Koha::Objects->reset();
Lines 177-183 with the first object in a set. Link Here
177
sub reset {
171
sub reset {
178
    my ( $self ) = @_;
172
    my ( $self ) = @_;
179
173
180
    $self->_resultset()->reset();
174
    $self->{_iterator} = 0;
181
175
182
    return $self;
176
    return $self;
183
}
177
}
Lines 193-203 Returns an arrayref of the objects in this set. Link Here
193
sub as_list {
187
sub as_list {
194
    my ( $self ) = @_;
188
    my ( $self ) = @_;
195
189
196
    my @dbic_rows = $self->_resultset()->all();
190
    my $objects = $self->_objects();
191
192
    return wantarray ? @$objects : $objects;
193
}
194
195
=head3 Koha::Objects->_objects
196
197
Returns an arrayref of all the objects that are part of this Objects set
198
199
=cut
200
201
sub _objects {
202
    my ( $self ) = @_;
197
203
198
    my @objects = $self->_wrap(@dbic_rows);
204
    $self->{_objects} ||= $self->_wrap( $self->_resultset()->all() );
199
205
200
    return wantarray ? @objects : \@objects;
206
    return $self->{_objects};
201
}
207
}
202
208
203
=head3 Koha::Objects->_wrap
209
=head3 Koha::Objects->_wrap
Lines 211-217 sub _wrap { Link Here
211
217
212
    my @objects = map { $self->object_class()->_new_from_dbic( $_ ) } @dbic_rows;
218
    my @objects = map { $self->object_class()->_new_from_dbic( $_ ) } @dbic_rows;
213
219
214
    return @objects;
220
    return wantarray ? @objects : \@objects;;
215
}
221
}
216
222
217
=head3 Koha::Objects->_resultset
223
=head3 Koha::Objects->_resultset
218
- 

Return to bug 13019