The synopsis was a little goofy
[gitmo/MooseX-AttributeHelpers.git] / lib / MooseX / AttributeHelpers / Bool.pm
1 package MooseX::AttributeHelpers::Bool;
2 use Moose;
3 use MooseX::AttributeHelpers::MethodProvider::Bool;
4
5 our $VERSION   = '0.14';
6 $VERSION = eval $VERSION;
7 our $AUTHORITY = 'cpan:STEVAN';
8
9 extends 'MooseX::AttributeHelpers::Base';
10
11 sub helper_type { 'Bool' }
12
13 # NOTE:
14 # we don't use the method provider for this 
15 # module since many of the names of the provied
16 # methods would conflict with keywords
17 # - SL
18
19 has '+method_provider' => (
20     default => 'MooseX::AttributeHelpers::MethodProvider::Bool'
21 );
22     
23 no Moose;
24
25 # register the alias ...
26 package # hide me from search.cpan.org
27     Moose::Meta::Attribute::Custom::Bool;
28 sub register_implementation { 'MooseX::AttributeHelpers::Bool' }
29
30 1;
31
32 =pod
33
34 =head1 NAME
35
36 MooseX::AttributeHelpers::Bool
37
38 =head1 SYNOPSIS
39   
40   package Room;
41   use Moose;
42   use MooseX::AttributeHelpers;
43   
44   has 'is_lit' => (
45       metaclass => 'Bool',
46       is        => 'rw',
47       isa       => 'Bool',
48       default   => sub { 0 },
49       provides  => {
50           set     => 'illuminate',
51           unset   => 'darken',
52           toggle  => 'flip_switch',
53           not     => 'is_dark'
54       }
55   );
56
57   my $room = Room->new();
58   $room->illuminate;     # same as $room->is_lit(1);
59   $room->darken;         # same as $room->is_lit(0);
60   $room->flip_switch;    # same as $room->is_lit(not $room->is_lit);
61   return $room->is_dark; # same as !$room->is_lit
62   
63 =head1 DESCRIPTION
64
65 This provides a simple boolean attribute, which supports most of the
66 basic math operations.
67
68 =head1 METHODS
69
70 =over 4
71
72 =item B<meta>
73
74 =item B<helper_type>
75
76 =item B<method_constructors>
77
78 =item B<has_method_provider>
79
80 =item B<method_provider>
81
82 =back
83
84 =head1 PROVIDED METHODS
85
86 It is important to note that all those methods do in place
87 modification of the value stored in the attribute.
88
89 =over 4
90
91 =item I<set>
92
93 Sets the value to C<1>.
94
95 =item I<unset>
96
97 Set the value to C<0>.
98
99 =item I<toggle>
100
101 Toggle the value. If it's true, set to false, and vice versa.
102
103 =item I<not>
104
105 Equivalent of 'not C<$value>'.
106
107 =back
108
109 =head1 BUGS
110
111 All complex software has bugs lurking in it, and this module is no 
112 exception. If you find a bug please either email me, or add the bug
113 to cpan-RT.
114
115 =head1 AUTHOR
116
117 Jason May
118
119 =head1 COPYRIGHT AND LICENSE
120
121 Copyright 2007-2008 by Infinity Interactive, Inc.
122
123 L<http://www.iinteractive.com>
124
125 This library is free software; you can redistribute it and/or modify
126 it under the same terms as Perl itself.
127
128 =cut