NAME

Scalar::Boolean - Makes scalar variables store Boolean values only

VERSION

version 1.02

SYNOPSIS

use Scalar::Boolean;

bool my $value;
$value = [];       # $value gets set to 1
$value = 'Perl';   # $value gets set to 1
$value = '';       # $value gets set to 0
$value = '0';      # $value gets set to 0
$value = undef;    # $value gets set to 0
$value = ();       # $value gets set to 0

unbool $value;
$value = 'foo';  # $value gets set to 'foo'

boolean [];     # returns 1
boolean undef;  # returns 0

METHODS

bool or booleanise or booleanize

Accepts scalar variables which will be booleanised. Once booleanised, the variable will convert all values that are assigned to it to their corresponding Boolean values. No effect on already booleanised variables.

unbool or unbooleanise or unbooleanize

Accepts scalar variables which will be unbooleanised if already booleanised. No effect on not already booleanised variables.

boolean

Accepts a single value and returns its boolean value without affecting its original value.

PERFORMANCE

For performance reasons, Scalar::Boolean prefers Variable::Magic if it is installed, else uses Tie::Scalar for magic.

ACKNOWLEDGEMENT

Many thanks to Eric Brine (ikegami) for suggesting several improvements, for valuable suggestions and also for sending sample code. Thank you Eric! :-)

AUTHOR

Alan Haggai Alavi <alanhaggai@alanhaggai.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2012 by Alan Haggai Alavi.

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