Bug 21022: (follow-up) Move overloaded full_message method to subclass
authorTomas Cohen Arazi <tomascohen@theke.io>
Fri, 29 Jun 2018 14:15:22 +0000 (11:15 -0300)
committerNick Clemens <nick@bywatersolutions.com>
Fri, 13 Jul 2018 13:25:15 +0000 (13:25 +0000)
We shouldn't have it overloaded on the base class, as it could get huge
and difficult to find things, and read.

This patch moves things to Koha::Exceptions::Object. We should overload
the full_message method on each exceptions class, as needed.

To test:
- Run:
  $ kshell
 k$ prove t/Koha/Exceptions.t
=> SUCCESS: Tests still pass!
- Sign off :-D

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Koha/Exceptions/Exception.pm
Koha/Exceptions/Object.pm

index 3b311b8..8955ea9 100644 (file)
@@ -9,19 +9,4 @@ use Exception::Class (
     },
 );
 
-# We want to overload it to have a stringification method for our exceptions
-sub full_message {
-    my $self = shift;
-
-    my $msg = $self->message;
-
-    unless ( $msg) {
-        if ( $self->isa('Koha::Exceptions::Object::FKConstraint') ) {
-            $msg = sprintf("Invalid parameter passed, %s=%s does not exist", $self->broken_fk, $self->value );
-        }
-    }
-
-    return $msg;
-}
-
 1;
index 8115640..9569182 100644 (file)
@@ -1,5 +1,20 @@
 package Koha::Exceptions::Object;
 
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 3 of the License, or (at your option) any later
+# version.
+#
+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with Koha; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
 use Modern::Perl;
 
 use Koha::Exceptions::Exception;
@@ -32,4 +47,56 @@ use Exception::Class (
     },
 );
 
+sub full_message {
+    my $self = shift;
+
+    my $msg = $self->message;
+
+    unless ( $msg) {
+        if ( $self->isa('Koha::Exceptions::Object::FKConstraint') ) {
+            $msg = sprintf("Invalid parameter passed, %s=%s does not exist", $self->broken_fk, $self->value );
+        }
+    }
+
+    return $msg;
+}
+
+=head1 NAME
+
+Koha::Exceptions::Object - Base class for Object exceptions
+
+=head1 Exceptions
+
+=head2 Koha::Exceptions::Object
+
+Generic Object exception
+
+=head2 Koha::Exceptions::Object::DuplicateID
+
+Exception to be used when a duplicate ID is passed.
+
+=head2 Koha::Exceptions::Object::FKConstraint
+
+Exception to be used when a foreign key constraint is broken.
+
+=head2 Koha::Exceptions::Object::MethodNotFound
+
+Exception to be used when an invalid class method has been invoked.
+
+=head2 Koha::Exceptions::Object::PropertyNotFound
+
+Exception to be used when an invalid object property has been requested.
+
+=head2 Koha::Exceptions::Object::MethodNotCoveredByTests
+
+Exception to be used when the invoked method is not covered by tests.
+
+=head1 Class methods
+
+=head2 full_message
+
+Overloaded method for exception stringifying.
+
+=cut
+
 1;