Scalar::Boolean - Makes scalar variables store Boolean values only
version 1.02
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
bool
booleanise
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
unbooleanise
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.
For performance reasons, Scalar::Boolean prefers Variable::Magic if it is installed, else uses Tie::Scalar for magic.
Many thanks to Eric Brine (ikegami) for suggesting several improvements, for valuable suggestions and also for sending sample code. Thank you Eric! :-)
Alan Haggai Alavi <alanhaggai@alanhaggai.org>
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.
To install Scalar::Boolean, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Scalar::Boolean
CPAN shell
perl -MCPAN -e shell install Scalar::Boolean
For more information on module installation, please visit the detailed CPAN module installation guide.