076b232bfeeb9f10dbb900d353f4cbca8d5e7f92
[gitmo/Moose.git] / lib / Moose / Meta / Attribute / Native / Trait / Bool.pm
1 package Moose::Meta::Attribute::Native::Trait::Bool;
2 use Moose::Role;
3
4 with 'Moose::Meta::Attribute::Native::Trait';
5
6 sub _default_is  { 'rw' }
7 sub _helper_type { 'Bool' }
8
9 no Moose::Role;
10
11 1;
12
13 =pod
14
15 =head1 SYNOPSIS
16
17   package Room;
18   use Moose;
19
20   has 'is_lit' => (
21       traits  => ['Bool'],
22       is      => 'rw',
23       isa     => 'Bool',
24       default => 0,
25       handles => {
26           illuminate  => 'set',
27           darken      => 'unset',
28           flip_switch => 'toggle',
29           is_dark     => 'not',
30       },
31   );
32
33   my $room = Room->new();
34   $room->illuminate;        # same as $room->is_lit(1);
35   $room->darken;            # same as $room->is_lit(0);
36   $room->flip_switch;       # same as $room->is_lit(not $room->is_lit);
37   return $room->is_dark;    # same as !$room->is_lit
38
39 =head1 DESCRIPTION
40
41 This trait provides native delegation methods for boolean values. A boolean is
42 a scalar which can be C<1>, C<0>, C<"">, or C<undef>.
43
44 =head1 DEFAULT TYPE
45
46 If you don't provide an C<isa> value for your attribute, it will default to
47 C<Bool>.
48
49 =head1 PROVIDED METHODS
50
51 None of these methods accept arguments.
52
53 =over 4
54
55 =item * B<set>
56
57 Sets the value to C<1> and returns C<1>.
58
59 =item * B<unset>
60
61 Set the value to C<0> and returns C<0>.
62
63 =item * B<toggle>
64
65 Toggles the value. If it's true, set to false, and vice versa.
66
67 Returns the new value.
68
69 =item * B<not>
70
71 Equivalent of 'not C<$value>'.
72
73 =back
74
75 =head1 BUGS
76
77 See L<Moose/BUGS> for details on reporting bugs.
78
79 =cut