Boolean::String - Strings with boolean values independent of perl's assumptions
version 0.01
use Boolean::String; $message = false 'Record not found'; $message = true 'Record found';
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.
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 '...';
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 '...';
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.
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 handles the importing of the functions, so if you want to do something fancy, that's where you can find out how.
everybody <everybody at cpan.org>
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.
To install Boolean::String, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Boolean::String
CPAN shell
perl -MCPAN -e shell install Boolean::String
For more information on module installation, please visit the detailed CPAN module installation guide.