[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
Mon Jan 3 15:42:08 CET 2022


https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=29746

--- Comment #10 from Jonathan Druart <jonathan.druart+koha at gmail.com> ---
(In reply to Jonathan Druart from comment #9)
> +use overload bool => \&as_bool;
> 
> I didn't notice that the first time I read this patch, and it's awesome!
> 
> I will provide you a QA feedback soon.

And, to explain a bit more:

"""
use Koha::Result::Boolean;
sub ok {
    return Koha::Result::Boolean->new(1)->add_message({message => "this is not
an error"});
}
sub nok {
    return Koha::Result::Boolean->new(0)->add_message({message => "this is an
error"});
}

if ( ok() ) { 
    say "all good";
}
unless ( nok() ) { 
    say "there was an error";
}
"""

=> will display "all good" and "there was an error"

-- 
You are receiving this mail because:
You are watching all bug changes.


More information about the Koha-bugs mailing list