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