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 | |
96539d20 |
5 | our $VERSION = '0.87'; |
e3c07b19 |
6 | $VERSION = eval $VERSION; |
7 | our $AUTHORITY = 'cpan:STEVAN'; |
8 | |
c466e58f |
9 | with 'Moose::Meta::Attribute::Native::Trait'; |
e3c07b19 |
10 | |
2edb73d9 |
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 | |
c466e58f |
32 | Moose::Meta::Attribute::Native::Trait::Bool |
e3c07b19 |
33 | |
34 | =head1 SYNOPSIS |
35 | |
36 | package Room; |
37 | use Moose; |
38 | use Moose::AttributeHelpers; |
39 | |
40 | has 'is_lit' => ( |
41 | metaclass => 'Bool', |
42 | is => 'rw', |
43 | isa => 'Bool', |
2edb73d9 |
44 | default => 0, |
5f3663b2 |
45 | handles => { |
46 | illuminate => 'set', |
47 | darken => 'unset', |
48 | flip_switch => 'toggle', |
49 | is_dark => 'not', |
e3c07b19 |
50 | } |
51 | ); |
52 | |
53 | my $room = Room->new(); |
54 | $room->illuminate; # same as $room->is_lit(1); |
55 | $room->darken; # same as $room->is_lit(0); |
56 | $room->flip_switch; # same as $room->is_lit(not $room->is_lit); |
57 | return $room->is_dark; # same as !$room->is_lit |
58 | |
59 | =head1 DESCRIPTION |
60 | |
61 | This provides a simple boolean attribute, which supports most of the |
62 | basic math operations. |
63 | |
64 | =head1 METHODS |
65 | |
66 | =over 4 |
67 | |
68 | =item B<meta> |
69 | |
e3c07b19 |
70 | =item B<method_constructors> |
71 | |
72 | =item B<has_method_provider> |
73 | |
74 | =item B<method_provider> |
75 | |
76 | =back |
77 | |
78 | =head1 PROVIDED METHODS |
79 | |
80 | It is important to note that all those methods do in place |
81 | modification of the value stored in the attribute. |
82 | |
83 | =over 4 |
84 | |
85 | =item I<set> |
86 | |
87 | Sets the value to C<1>. |
88 | |
89 | =item I<unset> |
90 | |
91 | Set the value to C<0>. |
92 | |
93 | =item I<toggle> |
94 | |
95 | Toggle the value. If it's true, set to false, and vice versa. |
96 | |
97 | =item I<not> |
98 | |
99 | Equivalent of 'not C<$value>'. |
100 | |
101 | =back |
102 | |
103 | =head1 BUGS |
104 | |
105 | All complex software has bugs lurking in it, and this module is no |
106 | exception. If you find a bug please either email me, or add the bug |
107 | to cpan-RT. |
108 | |
109 | =head1 AUTHOR |
110 | |
111 | Jason May |
112 | |
113 | =head1 COPYRIGHT AND LICENSE |
114 | |
115 | Copyright 2007-2009 by Infinity Interactive, Inc. |
116 | |
117 | L<http://www.iinteractive.com> |
118 | |
119 | This library is free software; you can redistribute it and/or modify |
120 | it under the same terms as Perl itself. |
121 | |
122 | =cut |