{
    "mode": "perldoc",
    "parameter": "boolean",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/boolean/json",
    "generated": "2026-06-16T03:36:45Z",
    "synopsis": "use boolean;\ndo &always if true;\ndo &never if false;\ndo &maybe if boolean($value)->isTrue;\nand:\nuse boolean ':all';\n$guess = int(rand(2)) % 2 ? true : false;\ndo &something if isTrue($guess);\ndo &somethingelse if isFalse($guess);",
    "sections": {
        "NAME": {
            "content": "boolean - Boolean support for Perl\n",
            "subsections": []
        },
        "VERSION": {
            "content": "This document describes boolean version 0.46.\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use boolean;\n\ndo &always if true;\ndo &never if false;\n\ndo &maybe if boolean($value)->isTrue;\n\nand:\n\nuse boolean ':all';\n\n$guess = int(rand(2)) % 2 ? true : false;\n\ndo &something if isTrue($guess);\ndo &somethingelse if isFalse($guess);\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "Most programming languages have a native \"Boolean\" data type. Perl does not.\n\nPerl has a simple and well known Truth System. The following scalar values are false:\n\n$false1 = undef;\n$false2 = 0;\n$false3 = 0.0;\n$false4 = '';\n$false5 = '0';\n\nEvery other scalar value is true.\n\nThis module provides basic Boolean support, by defining two special objects: \"true\" and \"false\".\n",
            "subsections": []
        },
        "RATIONALE": {
            "content": "When sharing data between programming languages, it is important to support the same group of\nbasic types. In Perlish programming languages, these types include: Hash, Array, String, Number,\nNull and Boolean. Perl lacks native Boolean support.\n\nData interchange modules like YAML and JSON can now \"use boolean\" to encode*decode*roundtrip\nBoolean values.\n",
            "subsections": []
        },
        "FUNCTIONS": {
            "content": "This module defines the following functions:\n\n\"true\"\nThis function returns a scalar value which will evaluate to true. The value is a singleton\nobject, meaning there is only one \"true\" value in a Perl process at any time. You can check\nto see whether the value is the \"true\" object with the isTrue function described below.\n\n\"false\"\nThis function returns a scalar value which will evaluate to false. The value is a singleton\nobject, meaning there is only one \"false\" value in a Perl process at any time. You can check\nto see whether the value is the \"false\" object with the isFalse function described below.\n\n\"boolean($scalar)\"\nCasts the scalar value to a boolean value. If $scalar is true, it returns \"boolean::true\",\notherwise it returns \"boolean::false\".\n\n\"isTrue($scalar)\"\nReturns \"boolean::true\" if the scalar passed to it is the \"boolean::true\" object. Returns\n\"boolean::false\" otherwise.\n\n\"isFalse($scalar)\"\nReturns \"boolean::true\" if the scalar passed to it is the \"boolean::false\" object. Returns\n\"boolean::false\" otherwise.\n\n\"isBoolean($scalar)\"\nReturns \"boolean::true\" if the scalar passed to it is the \"boolean::true\" or\n\"boolean::false\" object. Returns \"boolean::false\" otherwise.\n",
            "subsections": []
        },
        "METHODS": {
            "content": "Since true and false return objects, you can call methods on them.\n\n\"$boolean->isTrue\"\nSame as isTrue($boolean).\n\n\"$boolean->isFalse\"\nSame as isFalse($boolean).\n",
            "subsections": []
        },
        "USE OPTIONS": {
            "content": "By default this module exports the \"true\", \"false\" and \"boolean\" functions.\n\nThe module also defines these export tags:\n\n\":all\"\nExports \"true\", \"false\", \"boolean\", \"isTrue\", \"isFalse\", \"isBoolean\"\n",
            "subsections": []
        },
        "DEPRECATIONS": {
            "content": "This module offered an export tag, \"-truth\", that overrides the Perl interpreter's internal\nvalues for true and false. This has been found to corrupt the interpreter in some circumstances.\nAlso, these overrides will no longer be possible as of Perl 5.22. Therefore, the \"-truth\" import\ntag is deprecated.\n",
            "subsections": []
        },
        "JSON SUPPORT": {
            "content": "JSON::MaybeXS (or less preferably JSON.pm ) will encode Perl data with boolean.pm values\ncorrectly if you use the \"convertblessed\" option:\n\nuse JSON::MaybeXS;\nuse boolean -truth;\nmy $json = JSON::MaybeXS->new->convertblessed;\nsay $json->encode({false => (0 == 1)});     # Says: '{\"false\":false}',\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "Ingy döt Net <ingy@cpan.org>\n",
            "subsections": []
        },
        "COPYRIGHT AND LICENSE": {
            "content": "Copyright 2007-2016. Ingy döt Net.\n\nThis program is free software; you can redistribute it and/or modify it under the same terms as\nPerl itself.\n\nSee <http://www.perl.com/perl/misc/Artistic.html>\n",
            "subsections": []
        }
    },
    "summary": "boolean - Boolean support for Perl",
    "flags": [],
    "examples": [],
    "see_also": []
}