Bug 26922: Regression tests
[koha.git] / Koha / Exceptions / Object.pm
blob688a97cd5a470b2e574da557d00e0a9c275d07ff
1 package Koha::Exceptions::Object;
3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
18 use Modern::Perl;
20 use Koha::Exceptions::Exception;
22 use Exception::Class (
23 'Koha::Exceptions::Object' => {
24 isa => 'Koha::Exceptions::Exception',
26 'Koha::Exceptions::Object::DuplicateID' => {
27 isa => 'Koha::Exceptions::Object',
28 description => "Duplicate ID passed",
29 fields => ['duplicate_id']
31 'Koha::Exceptions::Object::FKConstraint' => {
32 isa => 'Koha::Exceptions::Object',
33 description => "Foreign key constraint broken",
34 fields => ['broken_fk', 'value'],
36 'Koha::Exceptions::Object::MethodNotFound' => {
37 isa => 'Koha::Exceptions::Object',
38 description => "Invalid method",
40 'Koha::Exceptions::Object::PropertyNotFound' => {
41 isa => 'Koha::Exceptions::Object',
42 description => "Invalid property",
44 'Koha::Exceptions::Object::ReadOnlyProperty' => {
45 isa => 'Koha::Exceptions::Object',
46 description => "Change of readonly property attempted",
47 fields => [ 'property' ],
49 'Koha::Exceptions::Object::MethodNotCoveredByTests' => {
50 isa => 'Koha::Exceptions::Object',
51 description => "Method not covered by tests",
53 'Koha::Exceptions::Object::BadValue' => {
54 isa => 'Koha::Exceptions::Object',
55 description => 'Invalid data passed',
56 fields => ['type', 'property', 'value'],
58 'Koha::Exceptions::Object::NotInstantiated' => {
59 isa => 'Koha::Exceptions::Object',
60 description => 'Tried to access a method on an uninstantiated object',
61 fields => ['class','method']
63 'Koha::Exceptions::Object::NotInStorage' => {
64 isa => 'Koha::Exceptions::Object',
65 description => 'The object is not in storage yet',
69 sub full_message {
70 my $self = shift;
72 my $msg = $self->message;
74 unless ( $msg) {
75 if ( $self->isa('Koha::Exceptions::Object::FKConstraint') ) {
76 $msg = sprintf("Invalid parameter passed, %s=%s does not exist", $self->broken_fk, $self->value );
78 elsif ( $self->isa('Koha::Exceptions::Object::BadValue') ) {
79 $msg = sprintf("Invalid value passed, %s=%s expected type is %s", $self->property, $self->value, $self->type );
81 elsif ( $self->isa('Koha::Exceptions::Object::ReadOnlyProperty') ) {
82 $msg = sprintf("Invalid attempt to change readonly property: %s", $self->property );
84 elsif ( $self->isa('Koha::Exceptions::Object::NotInstantiated') ) {
85 $msg = sprintf("Tried to access the '%s' method, but %s is not instantiated", $self->method, $self->class );
89 return $msg;
92 =head1 NAME
94 Koha::Exceptions::Object - Base class for Object exceptions
96 =head1 Exceptions
98 =head2 Koha::Exceptions::Object
100 Generic Object exception
102 =head2 Koha::Exceptions::Object::DuplicateID
104 Exception to be used when a duplicate ID is passed.
106 =head2 Koha::Exceptions::Object::FKConstraint
108 Exception to be used when a foreign key constraint is broken.
110 =head2 Koha::Exceptions::Object::MethodNotFound
112 Exception to be used when an invalid class method has been invoked.
114 =head2 Koha::Exceptions::Object::PropertyNotFound
116 Exception to be used when an invalid object property has been requested.
118 =head2 Koha::Exceptions::Object::MethodNotCoveredByTests
120 Exception to be used when the invoked method is not covered by tests.
122 =head2 Koha::Exceptions::Object::BadValue
124 Exception to be used when a bad value has been passed for a property.
126 =head1 Class methods
128 =head2 full_message
130 Overloaded method for exception stringifying.
132 =cut