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