← Index
Performance Profile   « block view • line view • sub view »
For opac/opac-main.pl
  Run on Thu Jul 17 22:22:09 2008
Reported on Thu Jul 17 22:22:21 2008

FileC4/Boolean.pm
Statements Executed8
Total Time1.3e-05 seconds

Subroutines — ordered by inclusive time then name
CallsInclusive
Time
Subroutine
10.00003C4::Boolean::true_p
00C4::Boolean::BEGIN
00C4::Boolean::END

LineStmts.Exclusive
Time
Avg.Code
1package C4::Boolean;
2
3#package to handle Boolean values in the parameters table
4# Note: This is just a utility module; it should not be instantiated.
5
6
7# Copyright 2003 Katipo Communications
8#
9# This file is part of Koha.
10#
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.
15#
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.
19#
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
23
24use strict;
25use POSIX;
26
27use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
28
29BEGIN {
30 # set the version for version checking
31 $VERSION = 0.02;
32 require Exporter;
33 @EXPORT = qw(
34 &INVALID_BOOLEAN_STRING_EXCEPTION
35 );
36 @EXPORT_OK = qw(
37 true_p
38 );
39 @ISA = qw(Exporter);
40}
41
42=head1 NAME
43
44C4::Boolean - Convenience functions to handle boolean values
45in the parameter table
46
47=head1 SYNOPSIS
48
49 use C4::Boolean;
50
51=head1 DESCRIPTION
52
53In the parameter table, there are various Boolean values that
54variously require a 0/1, no/yes, false/true, or off/on values.
55This module aims to provide scripts a means to interpret these
56Boolean values in a consistent way which makes common sense.
57
58=head1 FUNCTIONS
59
60=over 2
61
62=cut
63
64sub INVALID_BOOLEAN_STRING_EXCEPTION ()
65 { 'The given value does not seem to be interpretable as a Boolean value' }
66
67use vars qw( %strings );
68
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,
77);
78
79=item true_p
80
81 if ( C4::Boolean::true_p(C4::Context->preference("insecure")) ) {
82 ...
83 }
84
85Tries to interpret the passed string as a Boolean value. Returns
86the value if the string can be interpreted as such; otherwise an
87exception is thrown.
88
89=cut
90
91
# spent 0.00003s within C4::Boolean::true_p which was called: # 1 times (0.00003s) by C4::Context::boolean_preference at line 475 of C4/Context.pm
sub true_p ($) {
9211e-061e-06 my($x) = @_;
93100 my $it;
9412e-062e-06 if (!defined $x || ref($x) ne '') {
95 die INVALID_BOOLEAN_STRING_EXCEPTION;
96 }
9711e-061e-06 $x = lc($x);
9814e-064e-06 $x =~ s/\s//g;
9912e-062e-06 if (defined $strings{$x}) {
100 $it = $strings{$x};
101 } else {
102 die INVALID_BOOLEAN_STRING_EXCEPTION;
103 }
10412e-062e-06 return $it;
105}
106
107
108#---------------------------------
109
11011e-061e-06END { } # module clean-up code here (global destructor)
111
1121;
113__END__
114
115=back
116
117=head1 AUTHOR
118
119Koha Developement team <info@koha.org>
120
121=cut