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