1 package Koha::Result::Boolean;
3 # Copyright ByWater Solutions 2021
4 # Copyright Theke Solutions 2021
6 # This file is part of Koha.
8 # Koha is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
13 # Koha is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with Koha; if not, see <http://www.gnu.org/licenses>.
27 use Koha::Object::Message;
31 Koha::Result::Boolean - Booleans, with extra Koha
39 my $bool = Koha::Result::Boolean->new( $value );
41 Constructor method to generate a Koha::Result::Boolean object. I<value> is
47 my ( $class, $value ) = @_;
49 $value //= 1; # default to true
50 $value = ($value) ? 1 : 0;
57 return bless ( $self, $class );
65 Set the boolean value for the object.
70 my ( $self, $value ) = @_;
72 $self->{value} = ($value) ? 1 : 0;
79 my @messages = @{ $bool->messages };
81 Returns the I<Koha::Object::Message> objects that were recorded.
88 $self->{_messages} = []
89 unless defined $self->{_messages};
91 return $self->{_messages};
100 payload => $payload ]
109 my ( $self, $params ) = @_;
111 push @{ $self->{_messages} }, Koha::Object::Message->new($params);
116 =head2 Internal methods
120 Internal method that exposes the boolean value of the object as a scalar.
127 return $self->{value} + 0;
132 Internal method implementing equality comparison in scalar context.
137 my ( $first, $second, $flipped ) = @_;
140 ? $first == $second->as_bool
141 : $first->as_bool == $second;
146 Tomas Cohen Arazi, E<lt>tomascohen@theke.ioE<gt>