fix the private shelf deletion in opac
[koha.git] / C4 / Boolean.pm
blobc9259df0358be54bb617ad8f83db5d4c28114847
1 package C4::Boolean;
3 #package to handle Boolean values in the parameters table
4 # Note: This is just a utility module; it should not be instantiated.
7 # Copyright 2003 Katipo Communications
9 # This file is part of Koha.
11 # Koha is free software; you can redistribute it and/or modify it under the
12 # terms of the GNU General Public License as published by the Free Software
13 # Foundation; either version 2 of the License, or (at your option) any later
14 # version.
16 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
17 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
18 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License along with
21 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
22 # Suite 330, Boston, MA 02111-1307 USA
24 use strict;
25 use POSIX;
27 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
29 BEGIN {
30 # set the version for version checking
31 $VERSION = 0.02;
32 require Exporter;
33 @EXPORT = qw(
34 &INVALID_BOOLEAN_STRING_EXCEPTION
36 @EXPORT_OK = qw(
37 true_p
39 @ISA = qw(Exporter);
42 =head1 NAME
44 C4::Boolean - Convenience functions to handle boolean values
45 in the parameter table
47 =head1 SYNOPSIS
49 use C4::Boolean;
51 =head1 DESCRIPTION
53 In the parameter table, there are various Boolean values that
54 variously require a 0/1, no/yes, false/true, or off/on values.
55 This module aims to provide scripts a means to interpret these
56 Boolean values in a consistent way which makes common sense.
58 =head1 FUNCTIONS
60 =over 2
62 =cut
64 sub INVALID_BOOLEAN_STRING_EXCEPTION ()
65 { 'The given value does not seem to be interpretable as a Boolean value' }
67 use vars qw( %strings );
69 %strings = (
70 '0' => 0, '1' => 1, # C
71 '-1' => 1, # BASIC
72 'nil' => 0, 't' => 1, # LISP
73 'false' => 0, 'true' => 1, # Pascal
74 'off' => 0, 'on' => 1,
75 'no' => 0, 'yes' => 1,
76 'n' => 0, 'y' => 1,
79 =item true_p
81 if ( C4::Boolean::true_p(C4::Context->preference("insecure")) ) {
82 ...
85 Tries to interpret the passed string as a Boolean value. Returns
86 the value if the string can be interpreted as such; otherwise an
87 exception is thrown.
89 =cut
91 sub true_p ($) {
92 my($x) = @_;
93 my $it;
94 if (!defined $x || ref($x) ne '') {
95 die INVALID_BOOLEAN_STRING_EXCEPTION;
97 $x = lc($x);
98 $x =~ s/\s//g;
99 if (defined $strings{$x}) {
100 $it = $strings{$x};
101 } else {
102 die INVALID_BOOLEAN_STRING_EXCEPTION;
104 return $it;
108 #---------------------------------
110 END { } # module clean-up code here (global destructor)
113 __END__
115 =back
117 =head1 AUTHOR
119 Koha Developement team <info@koha.org>
121 =cut