Filename | /mnt/catalyst/koha/C4/Boolean.pm |
Statements | Executed 14 statements in 2.13ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 2.33ms | 2.63ms | BEGIN@55 | C4::Boolean::
1 | 1 | 1 | 1.81ms | 1.95ms | BEGIN@28 | C4::Boolean::
1 | 1 | 1 | 533µs | 551µs | BEGIN@24 | C4::Boolean::
1 | 1 | 1 | 11µs | 50µs | BEGIN@27 | C4::Boolean::
1 | 1 | 1 | 9µs | 17µs | BEGIN@25 | C4::Boolean::
0 | 0 | 0 | 0s | 0s | true_p | C4::Boolean::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package 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 | ||||
21 | # with Koha; if not, write to the Free Software Foundation, Inc., | ||||
22 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||||
23 | |||||
24 | 2 | 36µs | 2 | 569µs | # spent 551µs (533+18) within C4::Boolean::BEGIN@24 which was called:
# once (533µs+18µs) by C4::Context::BEGIN@103 at line 24 # spent 551µs making 1 call to C4::Boolean::BEGIN@24
# spent 18µs making 1 call to strict::import |
25 | 2 | 26µs | 2 | 25µs | # spent 17µs (9+8) within C4::Boolean::BEGIN@25 which was called:
# once (9µs+8µs) by C4::Context::BEGIN@103 at line 25 # spent 17µs making 1 call to C4::Boolean::BEGIN@25
# spent 8µs making 1 call to warnings::import |
26 | |||||
27 | 2 | 30µs | 2 | 90µs | # spent 50µs (11+39) within C4::Boolean::BEGIN@27 which was called:
# once (11µs+39µs) by C4::Context::BEGIN@103 at line 27 # spent 50µs making 1 call to C4::Boolean::BEGIN@27
# spent 39µs making 1 call to Exporter::import |
28 | 2 | 860µs | 2 | 2.03ms | # spent 1.95ms (1.81+136µs) within C4::Boolean::BEGIN@28 which was called:
# once (1.81ms+136µs) by C4::Context::BEGIN@103 at line 28 # spent 1.95ms making 1 call to C4::Boolean::BEGIN@28
# spent 76µs making 1 call to base::import |
29 | |||||
30 | 1 | 2µs | our $VERSION = 3.07.00.049; | ||
31 | 1 | 900ns | our @EXPORT_OK = qw( true_p); | ||
32 | |||||
33 | =head1 NAME | ||||
34 | |||||
35 | C4::Boolean - Convenience function to handle boolean values | ||||
36 | in the parameter table | ||||
37 | |||||
38 | =head1 SYNOPSIS | ||||
39 | |||||
40 | use C4::Boolean; | ||||
41 | |||||
42 | =head1 DESCRIPTION | ||||
43 | |||||
44 | In the parameter table, there are various Boolean values that | ||||
45 | variously require a 0/1, no/yes, false/true, or off/on values. | ||||
46 | This module aims to provide scripts a means to interpret these | ||||
47 | Boolean values in a consistent way which makes common sense. | ||||
48 | |||||
49 | =head1 FUNCTIONS | ||||
50 | |||||
51 | =over 2 | ||||
52 | |||||
53 | =cut | ||||
54 | |||||
55 | 1 | 5µs | 1 | 44µs | # spent 2.63ms (2.33+300µs) within C4::Boolean::BEGIN@55 which was called:
# once (2.33ms+300µs) by C4::Context::BEGIN@103 at line 56 # spent 44µs making 1 call to constant::import |
56 | 1 | 1.16ms | 1 | 2.63ms | q{The given value does not seem to be interpretable as a Boolean value}; # spent 2.63ms making 1 call to C4::Boolean::BEGIN@55 |
57 | |||||
58 | 1 | 6µs | our %strings = ( | ||
59 | '0' => 0, '1' => 1, # C | ||||
60 | '-1' => 1, # BASIC | ||||
61 | 'nil' => 0, 't' => 1, # LISP | ||||
62 | 'false' => 0, 'true' => 1, # Pascal | ||||
63 | 'off' => 0, 'on' => 1, | ||||
64 | 'no' => 0, 'yes' => 1, | ||||
65 | 'n' => 0, 'y' => 1, | ||||
66 | ); | ||||
67 | |||||
68 | =item true_p | ||||
69 | |||||
70 | if ( C4::Boolean::true_p(C4::Context->preference("IndependentBranches")) ) { | ||||
71 | ... | ||||
72 | } | ||||
73 | |||||
74 | Tries to interpret the passed string as a Boolean value. Returns | ||||
75 | the value if the string can be interpreted as such; otherwise an | ||||
76 | exception is thrown. | ||||
77 | |||||
78 | =cut | ||||
79 | |||||
80 | sub true_p { | ||||
81 | my $x = shift; | ||||
82 | my $it; | ||||
83 | if (!defined $x || ref $x ) { | ||||
84 | carp INVALID_BOOLEAN_STRING_EXCEPTION; | ||||
85 | return; | ||||
86 | } | ||||
87 | $x = lc $x; | ||||
88 | $x =~ s/\s//g; | ||||
89 | if (defined $strings{$x}) { | ||||
90 | $it = $strings{$x}; | ||||
91 | } else { | ||||
92 | carp INVALID_BOOLEAN_STRING_EXCEPTION; | ||||
93 | } | ||||
94 | return $it; | ||||
95 | } | ||||
96 | |||||
97 | 1 | 6µs | 1; | ||
98 | __END__ |