File Coverage

blib/lib/Object/Boolean/YesNo.pm
Criterion Covered Total %
statement 9 9 100.0
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 12 12 100.0


line stmt bran cond sub pod time code
1             package Object::Boolean::YesNo;
2              
3 2     2   52853 use warnings;
  2         5  
  2         74  
4 2     2   12 use strict;
  2         3  
  2         97  
5              
6             our $VERSION = '0.02';
7              
8 2     2   11 use base 'Object::Boolean';
  2         5  
  2         1289  
9              
10             __PACKAGE__->strTrue('Yes');
11             __PACKAGE__->strFalse('No');
12              
13             =head1 NAME
14              
15             Object::Boolean::YesNo - Boolean objects which stringify to "Yes" or "No"
16              
17             =head1 SYNOPSIS
18              
19             use Object::Boolean::YesNo
20             True => { -as => 'Yes'}, # optional
21             False => { -as => 'No' }; # optional
22              
23             # The constructor will create a false object with a Perl
24             # false value or the word 'No'.
25             my $a = Object::Boolean::YesNo->new(0);
26             my $b = Object::Boolean::YesNo->new('No');
27              
28             # Anything else will be true :
29             my $c = Object::Boolean::YesNo->new(1);
30             my $d = Object::Boolean::YesNo->new('hippopotamus');
31              
32             # These objects stringify to 'Yes' and 'No'.
33             print $a; # No
34             print !$a; # Yes (negating produces another object)
35             print $c; # Yes
36             print $d; # Yes
37              
38             =head1 DESCRIPTION
39              
40             Boolean objects that stringify to 'Yes' and 'No', but behave like booleans
41             in boolean context. The constants (functions) True and False can be imported
42             as Yes and No as shown above.
43              
44             =head1 SEE ALSO
45              
46             Object::Boolean
47              
48             =head1 NOTES
49              
50             If you are using Class::DBI, and you have columns which represent booleans
51             as enum('Yes','No'), then doing this :
52              
53             __PACKAGE__->has_a(column_name => 'Object::Boolean::YesNo')
54              
55             will make column_name inflate and deflate into Object::Boolean::YesNo objects.
56              
57             =cut
58              
59             1;
60