Boolean/YesNo.pm

filter: Statementstmt 100% 13 / 13 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 100% 16 / 16 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« Boolean.pm ↑ Summary
1 package Object::Boolean::YesNo;
2  
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 our $VERSION = '0.02';
7  
8 3 ▶use base 'Object::Boolean';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 3 __PACKAGE__->strTrue('Yes');
11 3 __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 3 1;
60  
« Boolean.pm ↑ Summary