[Koha-bugs] [Bug 29746] Add a handy Koha::Result::Boolean class
bugzilla-daemon at bugs.koha-community.org
bugzilla-daemon at bugs.koha-community.org
Thu Jan 6 14:00:27 CET 2022
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=29746
Tomás Cohen Arazi <tomascohen at gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords|release-notes-needed |
Text to go in the| |This development introduces
release notes| |a new library,
| |Koha::Result::Boolean, that
| |will be used in method that
| |need to return a boolean,
| |but could also want to
| |carry some more information
| |such as the reason for a
| |'false' return value.
| |
| |A
| |Koha::Result::Boolean
| |object will be evaluated as
| |a boolean in bool context,
| |while retaining its object
| |nature and methods.
| |
| |For
| |example, suppose a $patron
| |object should not be
| |deleted because the patron
| |it represents has a
| |guarantee:
| |
| |```
| | if (
| |$patron->safe_to_delete ) {
| | ... }
| |```
| |
| |will eval to
| |false, and the code will do
| |what we expect.
| |
| |If our
| |code really wanted to know
| |*why* it cannot be
| |deleted, we can do:
| |
| |```
| |
| | my $result =
| |$patron->safe_to_delete;
| |
| | unless ( $result ) {
| |
| | Koha::Exceptions->throw(
| |"Cannot delete, errors: " .
| |join( ', ', map
| |{$_->message}
| |@{$result->messages} ) );
| |
| | }
| |```
--
You are receiving this mail because:
You are watching all bug changes.
More information about the Koha-bugs
mailing list