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