Lines 28-33
use Try::Tiny;
Link Here
|
28 |
use Koha::Database; |
28 |
use Koha::Database; |
29 |
use Koha::Exceptions::Object; |
29 |
use Koha::Exceptions::Object; |
30 |
use Koha::DateUtils; |
30 |
use Koha::DateUtils; |
|
|
31 |
use Koha::Object::Error; |
31 |
|
32 |
|
32 |
=head1 NAME |
33 |
=head1 NAME |
33 |
|
34 |
|
Lines 77-82
sub new {
Link Here
|
77 |
$schema->resultset( $class->_type() )->new($attributes); |
78 |
$schema->resultset( $class->_type() )->new($attributes); |
78 |
} |
79 |
} |
79 |
|
80 |
|
|
|
81 |
$self->{_errors} = []; |
82 |
|
80 |
croak("No _type found! Koha::Object must be subclassed!") |
83 |
croak("No _type found! Koha::Object must be subclassed!") |
81 |
unless $class->_type(); |
84 |
unless $class->_type(); |
82 |
|
85 |
|
Lines 332-337
sub get_from_storage {
Link Here
|
332 |
return $object_class->_new_from_dbic($stored_object); |
335 |
return $object_class->_new_from_dbic($stored_object); |
333 |
} |
336 |
} |
334 |
|
337 |
|
|
|
338 |
=head3 $object->errors |
339 |
|
340 |
my @errors = @{ $object->errors }; |
341 |
|
342 |
Returns the (probably non-fatal) errors that were recorded on the object. |
343 |
|
344 |
=cut |
345 |
|
346 |
sub errors { |
347 |
my ( $self ) = @_; |
348 |
return $self->{_errors}; |
349 |
} |
350 |
|
351 |
=head3 $object->add_error |
352 |
|
353 |
try { |
354 |
<some action that might fail> |
355 |
} |
356 |
catch { |
357 |
if ( <fatal condition> ) { |
358 |
Koha::Exception->throw... |
359 |
} |
360 |
|
361 |
# This is a non fatal error, notify the caller |
362 |
$self->add_error({ error => $error }); |
363 |
} |
364 |
return $self; |
365 |
|
366 |
Adds an error. |
367 |
|
368 |
=cut |
369 |
|
370 |
sub add_error { |
371 |
my ( $self, $params ) = @_; |
372 |
|
373 |
push @{ $self->{_errors} }, Koha::Object::Error->new($params); |
374 |
|
375 |
return $self; |
376 |
} |
377 |
|
335 |
=head3 $object->TO_JSON |
378 |
=head3 $object->TO_JSON |
336 |
|
379 |
|
337 |
Returns an unblessed representation of the object, suitable for JSON output. |
380 |
Returns an unblessed representation of the object, suitable for JSON output. |