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