NAME
Boolean::String - Strings with boolean values independent of perl's assumptions
VERSION
version 0.01
SYNOPSIS
use Boolean::String;
$message = false 'Record not found';
$message = true 'Record found';
DESCRIPTION
Boolean::String allows you to overload a string with a value in boolean context. Normally, perl considers all strings except the empty string to be true. Boolean::String allows you to change this assumption.
FUNCTIONS
true
This expects a single string, and returns an object that is true in boolean context and the passed in string in string context.
$true_string = true '...';
false
This expects a single string, and returns an object that is false in boolean context and the passed in string in string context.
$false_string = false '...';
IMPORTING
The functions are exported by default. Boolean::String uses Sub::Exporter for its import/export business. This makes it easy to change the names of the imported functions, like so:
# import 'true_because' and 'false_because'
use Boolean::String -all => { -suffix => '_because' };
# import 'success' and 'failure'
use Boolean::String true => { -as => 'success' }, false => { -as => 'failure' };
There's a whole slew of flexibility that Sub::Exporter brings to the table, so check it out if your importing needs are more involved than this.
SEE ALSO
Scalar::Util's dualvar
dualvar allows you to have different values for numeric and string contexts. Unfortunately, Boolean::String's functionality cannot be implemented with this (simply setting the numeric value to 0/1), because perl derives a variable's value in boolean context from its value in string context, not numeric context.
Sub::Exporter's import semantics
Sub::Exporter handles the importing of the functions, so if you want to do something fancy, that's where you can find out how.
AUTHOR
everybody <everybody at cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2012 by everybody.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.