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