Object::Boolean::YesNo - Boolean objects which stringify to "Yes" or "No"
use Object::Boolean::YesNo True => { -as => 'Yes'}, # optional False => { -as => 'No' }; # optional # The constructor will create a false object with a Perl # false value or the word 'No'. my $a = Object::Boolean::YesNo->new(0); my $b = Object::Boolean::YesNo->new('No'); # Anything else will be true : my $c = Object::Boolean::YesNo->new(1); my $d = Object::Boolean::YesNo->new('hippopotamus'); # These objects stringify to 'Yes' and 'No'. print $a; # No print !$a; # Yes (negating produces another object) print $c; # Yes print $d; # Yes
Boolean objects that stringify to 'Yes' and 'No', but behave like booleans in boolean context. The constants (functions) True and False can be imported as Yes and No as shown above.
Object::Boolean
If you are using Class::DBI, and you have columns which represent booleans as enum('Yes','No'), then doing this :
__PACKAGE__->has_a(column_name => 'Object::Boolean::YesNo')
will make column_name inflate and deflate into Object::Boolean::YesNo objects.
To install Object::Boolean, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Object::Boolean
CPAN shell
perl -MCPAN -e shell install Object::Boolean
For more information on module installation, please visit the detailed CPAN module installation guide.