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