1boolean(3)            User Contributed Perl Documentation           boolean(3)
2
3
4

NAME

6       boolean - Boolean support for Perl
7

VERSION

9       This document describes boolean version 0.46.
10

SYNOPSIS

12           use boolean;
13
14           do &always if true;
15           do &never if false;
16
17           do &maybe if boolean($value)->isTrue;
18
19       and:
20
21           use boolean ':all';
22
23           $guess = int(rand(2)) % 2 ? true : false;
24
25           do &something if isTrue($guess);
26           do &something_else if isFalse($guess);
27

DESCRIPTION

29       Most programming languages have a native "Boolean" data type. Perl does
30       not.
31
32       Perl has a simple and well known Truth System. The following scalar
33       values are false:
34
35           $false1 = undef;
36           $false2 = 0;
37           $false3 = 0.0;
38           $false4 = '';
39           $false5 = '0';
40
41       Every other scalar value is true.
42
43       This module provides basic Boolean support, by defining two special
44       objects: "true" and "false".
45

RATIONALE

47       When sharing data between programming languages, it is important to
48       support the same group of basic types. In Perlish programming
49       languages, these types include: Hash, Array, String, Number, Null and
50       Boolean. Perl lacks native Boolean support.
51
52       Data interchange modules like YAML and JSON can now "use boolean" to
53       encodedecoderoundtrip Boolean values.
54

FUNCTIONS

56       This module defines the following functions:
57
58       "true"
59           This function returns a scalar value which will evaluate to true.
60           The value is a singleton object, meaning there is only one "true"
61           value in a Perl process at any time. You can check to see whether
62           the value is the "true" object with the isTrue function described
63           below.
64
65       "false"
66           This function returns a scalar value which will evaluate to false.
67           The value is a singleton object, meaning there is only one "false"
68           value in a Perl process at any time. You can check to see whether
69           the value is the "false" object with the isFalse function described
70           below.
71
72       "boolean($scalar)"
73           Casts the scalar value to a boolean value. If $scalar is true, it
74           returns "boolean::true", otherwise it returns "boolean::false".
75
76       "isTrue($scalar)"
77           Returns "boolean::true" if the scalar passed to it is the
78           "boolean::true" object. Returns "boolean::false" otherwise.
79
80       "isFalse($scalar)"
81           Returns "boolean::true" if the scalar passed to it is the
82           "boolean::false" object. Returns "boolean::false" otherwise.
83
84       "isBoolean($scalar)"
85           Returns "boolean::true" if the scalar passed to it is the
86           "boolean::true" or "boolean::false" object. Returns
87           "boolean::false" otherwise.
88

METHODS

90       Since true and false return objects, you can call methods on them.
91
92       "$boolean->isTrue"
93           Same as isTrue($boolean).
94
95       "$boolean->isFalse"
96           Same as isFalse($boolean).
97

USE OPTIONS

99       By default this module exports the "true", "false" and "boolean"
100       functions.
101
102       The module also defines these export tags:
103
104       ":all"
105           Exports "true", "false", "boolean", "isTrue", "isFalse",
106           "isBoolean"
107

DEPRECATIONS

109       This module offered an export tag, "-truth", that overrides the Perl
110       interpreter's internal values for true and false. This has been found
111       to corrupt the interpreter in some circumstances. Also, these overrides
112       will no longer be possible as of Perl 5.22. Therefore, the "-truth"
113       import tag is deprecated.
114

JSON SUPPORT

116       JSON::MaybeXS (or less preferably JSON.pm ) will encode Perl data with
117       boolean.pm values correctly if you use the "convert_blessed" option:
118
119           use JSON::MaybeXS;
120           use boolean -truth;
121           my $json = JSON::MaybeXS->new->convert_blessed;
122           say $json->encode({false => (0 == 1)});     # Says: '{"false":false}',
123

AUTHOR

125       Ingy döt Net <ingy@cpan.org>
126
128       Copyright 2007-2016. Ingy döt Net.
129
130       This program is free software; you can redistribute it and/or modify it
131       under the same terms as Perl itself.
132
133       See <http://www.perl.com/perl/misc/Artistic.html>
134
135
136
137perl v5.32.1                      2021-01-27                        boolean(3)
Impressum