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