5 #package to handle Boolean values in the parameters table
6 # Note: This is just a utility module; it should not be instantiated.
9 # Copyright 2003 Katipo Communications
11 # This file is part of Koha.
13 # Koha is free software; you can redistribute it and/or modify it under the
14 # terms of the GNU General Public License as published by the Free Software
15 # Foundation; either version 2 of the License, or (at your option) any later
18 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
19 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
20 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
22 # You should have received a copy of the GNU General Public License along with
23 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
24 # Suite 330, Boston, MA 02111-1307 USA
30 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
32 # set the version for version checking
37 C4::Boolean - Convenience functions to handle boolean values
38 in the parameter table
46 In the parameter table, there are various Boolean values that
47 variously require a 0/1, no/yes, false/true, or off/on values.
48 This module aims to provide scripts a means to interpret these
49 Boolean values in a consistent way which makes common sense.
59 &INVALID_BOOLEAN_STRING_EXCEPTION
66 sub INVALID_BOOLEAN_STRING_EXCEPTION ()
67 { 'The given value does not seem to be interpretable as a Boolean value' }
69 use vars qw( %strings );
72 '0' => 0, '1' => 1, # C
74 'nil' => 0, 't' => 1, # LISP
75 'false' => 0, 'true' => 1, # Pascal
76 'off' => 0, 'on' => 1,
77 'no' => 0, 'yes' => 1,
83 if ( C4::Boolean::true_p(C4::Context->preference("insecure")) ) {
87 Tries to interpret the passed string as a Boolean value. Returns
88 the value if the string can be interpreted as such; otherwise an
96 if (!defined $x || ref($x) ne '') {
97 die INVALID_BOOLEAN_STRING_EXCEPTION;
101 if (defined $strings{$x}) {
104 die INVALID_BOOLEAN_STRING_EXCEPTION;
110 #---------------------------------
112 END { } # module clean-up code here (global destructor)
121 Koha Developement team <info@koha.org>