Commit | Line | Data |
c466e58f |
1 | package Moose::Meta::Attribute::Native::Trait::Bool; |
e3c07b19 |
2 | use Moose::Role; |
e3c07b19 |
3 | |
245478d5 |
4 | our $VERSION = '1.19'; |
e3c07b19 |
5 | $VERSION = eval $VERSION; |
6 | our $AUTHORITY = 'cpan:STEVAN'; |
7 | |
c466e58f |
8 | with 'Moose::Meta::Attribute::Native::Trait'; |
e3c07b19 |
9 | |
55a9d564 |
10 | sub _default_is { 'rw' } |
2e069f5a |
11 | sub _helper_type { 'Bool' } |
2edb73d9 |
12 | |
e3c07b19 |
13 | no Moose::Role; |
14 | |
e3c07b19 |
15 | 1; |
16 | |
17 | =pod |
18 | |
19 | =head1 NAME |
20 | |
2420461c |
21 | Moose::Meta::Attribute::Native::Trait::Bool - Helper trait for Bool attributes |
e3c07b19 |
22 | |
23 | =head1 SYNOPSIS |
24 | |
25 | package Room; |
26 | use Moose; |
e3c07b19 |
27 | |
28 | has 'is_lit' => ( |
e132fd56 |
29 | traits => ['Bool'], |
30 | is => 'rw', |
31 | isa => 'Bool', |
32 | default => 0, |
33 | handles => { |
5f3663b2 |
34 | illuminate => 'set', |
35 | darken => 'unset', |
36 | flip_switch => 'toggle', |
37 | is_dark => 'not', |
9610c1d2 |
38 | }, |
e3c07b19 |
39 | ); |
40 | |
41 | my $room = Room->new(); |
e132fd56 |
42 | $room->illuminate; # same as $room->is_lit(1); |
43 | $room->darken; # same as $room->is_lit(0); |
44 | $room->flip_switch; # same as $room->is_lit(not $room->is_lit); |
45 | return $room->is_dark; # same as !$room->is_lit |
e3c07b19 |
46 | |
47 | =head1 DESCRIPTION |
48 | |
7795e4de |
49 | This trait provides native delegation methods for boolean values. A boolean is |
50 | a scalar which can be C<1>, C<0>, C<"">, or C<undef>. |
51 | |
52 | =head1 DEFAULT TYPE |
53 | |
54 | If you don't provide an C<isa> value for your attribute, it will default to |
55 | C<Bool>. |
e3c07b19 |
56 | |
e3c07b19 |
57 | =head1 PROVIDED METHODS |
58 | |
e132fd56 |
59 | None of these methods accept arguments. |
60 | |
e3c07b19 |
61 | =over 4 |
62 | |
e132fd56 |
63 | =item * B<set> |
e3c07b19 |
64 | |
e132fd56 |
65 | Sets the value to C<1> and returns C<1>. |
e3c07b19 |
66 | |
e132fd56 |
67 | =item * B<unset> |
e3c07b19 |
68 | |
e132fd56 |
69 | Set the value to C<0> and returns C<0>. |
e3c07b19 |
70 | |
e132fd56 |
71 | =item * B<toggle> |
e3c07b19 |
72 | |
157e0475 |
73 | Toggles the value. If it's true, set to false, and vice versa. |
e3c07b19 |
74 | |
e132fd56 |
75 | Returns the new value. |
55a9d564 |
76 | |
e132fd56 |
77 | =item * B<not> |
55a9d564 |
78 | |
e132fd56 |
79 | Equivalent of 'not C<$value>'. |
55a9d564 |
80 | |
55a9d564 |
81 | =back |
82 | |
e3c07b19 |
83 | =head1 BUGS |
84 | |
d4048ef3 |
85 | See L<Moose/BUGS> for details on reporting bugs. |
e3c07b19 |
86 | |
87 | =head1 AUTHOR |
88 | |
89 | Jason May |
90 | |
91 | =head1 COPYRIGHT AND LICENSE |
92 | |
93 | Copyright 2007-2009 by Infinity Interactive, Inc. |
94 | |
95 | L<http://www.iinteractive.com> |
96 | |
97 | This library is free software; you can redistribute it and/or modify |
98 | it under the same terms as Perl itself. |
99 | |
100 | =cut |