X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=C4%2FBoolean.pm;h=7ef9fc06744b4ce3c632b6f0f947cd68d6e57061;hb=12a8dfb934bf3819d6581f9df82987475334a302;hp=934a64f22c8c6a1ef20b94862d2083bec66a3da2;hpb=a244ff667199445ef5e81d5c8f976b34f5ac17b9;p=koha.git diff --git a/C4/Boolean.pm b/C4/Boolean.pm index 934a64f22c..7ef9fc0674 100644 --- a/C4/Boolean.pm +++ b/C4/Boolean.pm @@ -8,42 +8,30 @@ package C4::Boolean; # # 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 2 of the License, or (at your option) any later -# version. +# 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. +# 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., 59 Temple Place, -# Suite 330, Boston, MA 02111-1307 USA +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . use strict; use warnings; -use POSIX; - -use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); - -BEGIN { - # set the version for version checking - $VERSION = 0.02; - require Exporter; - @EXPORT = qw( - &INVALID_BOOLEAN_STRING_EXCEPTION - ); - @EXPORT_OK = qw( - true_p - ); - @ISA = qw(Exporter); -} +use Carp; +use base qw(Exporter); + +our @EXPORT_OK = qw( true_p); =head1 NAME -C4::Boolean - Convenience functions to handle boolean values +C4::Boolean - Convenience function to handle boolean values in the parameter table =head1 SYNOPSIS @@ -63,25 +51,23 @@ Boolean values in a consistent way which makes common sense. =cut -sub INVALID_BOOLEAN_STRING_EXCEPTION () - { 'The given value does not seem to be interpretable as a Boolean value' } - -use vars qw( %strings ); - -%strings = ( - '0' => 0, '1' => 1, # C - '-1' => 1, # BASIC - 'nil' => 0, 't' => 1, # LISP - 'false' => 0, 'true' => 1, # Pascal - 'off' => 0, 'on' => 1, - 'no' => 0, 'yes' => 1, - 'n' => 0, 'y' => 1, +use constant INVALID_BOOLEAN_STRING_EXCEPTION => + q{The given value does not seem to be interpretable as a Boolean value}; + +our %strings = ( + '0' => 0, '1' => 1, # C + '-1' => 1, # BASIC + 'nil' => 0, 't' => 1, # LISP + 'false' => 0, 'true' => 1, # Pascal + 'off' => 0, 'on' => 1, + 'no' => 0, 'yes' => 1, + 'n' => 0, 'y' => 1, ); =item true_p - if ( C4::Boolean::true_p(C4::Context->preference("insecure")) ) { - ... + if ( C4::Boolean::true_p(C4::Context->preference("IndependentBranches")) ) { + ... } Tries to interpret the passed string as a Boolean value. Returns @@ -90,27 +76,23 @@ exception is thrown. =cut -sub true_p ($) { - my($x) = @_; +sub true_p { + my $x = shift; my $it; - if (!defined $x || ref($x) ne '') { - die INVALID_BOOLEAN_STRING_EXCEPTION; + if (!defined $x || ref $x ) { + carp INVALID_BOOLEAN_STRING_EXCEPTION; + return; } - $x = lc($x); + $x = lc $x; $x =~ s/\s//g; if (defined $strings{$x}) { - $it = $strings{$x}; + $it = $strings{$x}; } else { - die INVALID_BOOLEAN_STRING_EXCEPTION; + carp INVALID_BOOLEAN_STRING_EXCEPTION; } return $it; } - -#--------------------------------- - -END { } # module clean-up code here (global destructor) - 1; __END__ @@ -118,6 +100,6 @@ __END__ =head1 AUTHOR -Koha Developement team +Koha Development Team =cut