Bug 13019 [QA Followup] - Allow chaining
authorKyle M Hall <kyle@bywatersolutions.com>
Tue, 10 Feb 2015 18:30:32 +0000 (13:30 -0500)
committerTomas Cohen Arazi <tomascohen@gmail.com>
Thu, 12 Feb 2015 18:21:13 +0000 (15:21 -0300)
By returning the object itself instead of a boolean, we can chain
methods together while retaining the exact same functionality.

Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
Koha/Object.pm
Koha/Objects.pm

index bc2746f..a77eb5c 100644 (file)
@@ -106,7 +106,7 @@ Returns:
 sub store {
     my ($self) = @_;
 
-    return $self->_result()->update_or_insert() ? 1 : 0;
+    return $self->_result()->update_or_insert() ? $self : undef;
 }
 
 =head3 $object->in_storage();
@@ -190,7 +190,7 @@ sub set {
         }
     }
 
-    return $self->_result()->set_columns($properties) ? 1 : undef;
+    return $self->_result()->set_columns($properties) ? $self : undef;
 }
 
 =head3 $object->id();
index 5413fb6..6b3100a 100644 (file)
@@ -80,6 +80,8 @@ my $object = Koha::Objects->find( { keypart1 => $keypart1, keypart2 => $keypart2
 sub find {
     my ( $self, $id ) = @_;
 
+    return unless $id;
+
     my $result = $self->_resultset()->find($id);
 
     my $object = $self->object_class()->_new_from_dbic( $result );