From ca4a096e03179d8ececd19e6bc6bd75d0eaf6631 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Fri, 29 Jun 2018 11:15:22 -0300 Subject: [PATCH] Bug 21022: (follow-up) Move overloaded full_message method to subclass 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 Signed-off-by: Jonathan Druart Signed-off-by: Nick Clemens Signed-off-by: Martin Renvoize --- Koha/Exceptions/Exception.pm | 15 -------- Koha/Exceptions/Object.pm | 67 ++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 15 deletions(-) diff --git a/Koha/Exceptions/Exception.pm b/Koha/Exceptions/Exception.pm index 3b311b8322..8955ea9e6e 100644 --- a/Koha/Exceptions/Exception.pm +++ b/Koha/Exceptions/Exception.pm @@ -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; diff --git a/Koha/Exceptions/Object.pm b/Koha/Exceptions/Object.pm index 81156400c9..9569182906 100644 --- a/Koha/Exceptions/Object.pm +++ b/Koha/Exceptions/Object.pm @@ -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; -- 2.39.5