Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Boolean Type Support for Perl

tag: 0.24

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 t
Octocat-spinner-32 Changes
Octocat-spinner-32 MANIFEST.SKIP
Octocat-spinner-32 Makefile.PL
Octocat-spinner-32 README
Octocat-spinner-32 ToDo
README
NAME
    boolean - Boolean support for Perl

SYNOPSIS
        use boolean;

        do &always if true;
        do &never if false;

        do &maybe if boolean($value)->is_true;

    With autobox:

        use autobox;
        use boolean;

        do &maybe if $value->is_true;

    and:

        use boolean ':all';

        $guess = int(rand(2)) % 2 ? true : false;

        do &something if isTrue($guess);
        do &something_else if isFalse($guess);

DESCRIPTION
    Most programming languages have a native "Boolean" data type. Perl does
    not.

    Perl has a simple and well known Truth System. The following scalar
    values are false:

        $false1 = undef;
        $false2 = 0;
        $false3 = 0.0;
        $false4 = '';
        $false5 = '0';

    Every other scalar value is true.

    This module provides basic Boolean support, by defining two special
    objects: "true" and "false".

RATIONALE
    When sharing data between programming languages, it is important to
    support the same group of basic types. In Perlish programming languages,
    these types include: Hash, Array, String, Number, Null and Boolean. Perl
    lacks native Boolean support.

    Data interchange modules like YAML and JSON can now "use boolean" to
    encode/decode/roundtrip Boolean values.

FUNCTIONS
    This module defines the following functions:

    true
        This function returns a scalar value which should evaluate to true.
        The value is a singleton object, meaning there is only one "true"
        value in a Perl process at any time. You can check to see whether
        the value is the "true" object with the isTrue function described
        below.

    false
        This function returns a scalar value which should evaluate to false.
        The value is a singleton object, meaning there is only one "false"
        value in a Perl process at any time. You can check to see whether
        the value is the "false" object with the isFalse function described
        below.

    boolean($scalar)
        Casts the scalar value to a boolean value. If $scalar is true, it
        returns "boolean::true", otherwise it returns "boolean::false".

    isTrue($scalar)
        Returns "boolean::true" if the scalar passed to it is the
        "boolean::true" object. Returns "boolean::false" otherwise.

    isFalse($scalar)
        Returns "boolean::true" if the scalar passed to it is the
        "boolean::false" object. Returns "boolean::false" otherwise.

    isBoolean($scalar)
        Returns "boolean::true" if the scalar passed to it is the
        "boolean::true" or "boolean::false" object. Returns "boolean::false"
        otherwise.

METHODS
    Since true and false return objects, you can call methods on them.

    $boolean->is_true
        Same as isTrue($boolean).

    $boolean->is_false
        Same as isFalse($boolean).

  autobox Methods
    If you use "boolean" with "autobox" you can call the following methods
    on any scalar:

    $scalar->boolean
        Same as boolean($scalar).

    $scalar->is_true
        Same as isTrue(boolean($scalar)).

    $scalar->is_false
        Same as isFalse(boolean($scalar)).

EXPORTABLES
    By default this module exports the "true", "false" and "boolean"
    functions.

    The module also defines these export tags:

    :all
        Exports "true", "false", "boolean", "isTrue", "isFalse", "isBoolean"

    :test
        Exports "isTrue", "isFalse", "isBoolean"

AUTHOR
    Ingy döt Net <ingy@cpan.org>

COPYRIGHT
    Copyright (c) 2007, 2008, 2010, 2011. Ingy döt Net.

    This program is free software; you can redistribute it and/or modify it
    under the same terms as Perl itself.

    See http://www.perl.com/perl/misc/Artistic.html
Something went wrong with that request. Please try again.