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