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::Message; |
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->{_messages} = []; |
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->messages |
339 |
|
340 |
my @messages = @{ $object->messages }; |
341 |
|
342 |
Returns the (probably non-fatal) messages that were recorded on the object. |
343 |
|
344 |
=cut |
345 |
|
346 |
sub messages { |
347 |
my ( $self ) = @_; |
348 |
return $self->{_messages}; |
349 |
} |
350 |
|
351 |
=head3 $object->add_message |
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_message({ message => $error, type => 'error' }); |
363 |
} |
364 |
return $self; |
365 |
|
366 |
Adds a message. |
367 |
|
368 |
=cut |
369 |
|
370 |
sub add_message { |
371 |
my ( $self, $params ) = @_; |
372 |
|
373 |
push @{ $self->{_messages} }, Koha::Object::Message->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. |