Bump version to 1.10
[gitmo/Moose.git] / lib / Moose / Meta / Attribute / Native / Trait / Bool.pm
CommitLineData
c466e58f 1package Moose::Meta::Attribute::Native::Trait::Bool;
e3c07b19 2use Moose::Role;
c466e58f 3use Moose::Meta::Attribute::Native::MethodProvider::Bool;
e3c07b19 4
db236a63 5our $VERSION = '1.10';
e3c07b19 6$VERSION = eval $VERSION;
7our $AUTHORITY = 'cpan:STEVAN';
8
c466e58f 9with 'Moose::Meta::Attribute::Native::Trait';
e3c07b19 10
55a9d564 11sub _default_is { 'rw' }
2e069f5a 12sub _helper_type { 'Bool' }
2edb73d9 13
e3c07b19 14has 'method_provider' => (
15 is => 'ro',
16 isa => 'ClassName',
17 predicate => 'has_method_provider',
c466e58f 18 default => 'Moose::Meta::Attribute::Native::MethodProvider::Bool'
e3c07b19 19);
20
e3c07b19 21no Moose::Role;
22
e3c07b19 231;
24
25=pod
26
27=head1 NAME
28
2420461c 29Moose::Meta::Attribute::Native::Trait::Bool - Helper trait for Bool attributes
e3c07b19 30
31=head1 SYNOPSIS
32
33 package Room;
34 use Moose;
e3c07b19 35
36 has 'is_lit' => (
9610c1d2 37 traits => ['Bool'],
e3c07b19 38 is => 'rw',
39 isa => 'Bool',
2edb73d9 40 default => 0,
5f3663b2 41 handles => {
42 illuminate => 'set',
43 darken => 'unset',
44 flip_switch => 'toggle',
45 is_dark => 'not',
9610c1d2 46 },
e3c07b19 47 );
48
49 my $room = Room->new();
50 $room->illuminate; # same as $room->is_lit(1);
51 $room->darken; # same as $room->is_lit(0);
52 $room->flip_switch; # same as $room->is_lit(not $room->is_lit);
53 return $room->is_dark; # same as !$room->is_lit
54
55=head1 DESCRIPTION
56
57This provides a simple boolean attribute, which supports most of the
58basic math operations.
59
e3c07b19 60=head1 PROVIDED METHODS
61
55a9d564 62These methods are implemented in
63L<Moose::Meta::Attribute::Native::MethodProvider::Bool>. It is important to
64note that all those methods do in place modification of the value stored in
65the attribute.
e3c07b19 66
67=over 4
68
eb465b32 69=item B<set>
e3c07b19 70
71Sets the value to C<1>.
72
eb465b32 73=item B<unset>
e3c07b19 74
75Set the value to C<0>.
76
eb465b32 77=item B<toggle>
e3c07b19 78
157e0475 79Toggles the value. If it's true, set to false, and vice versa.
e3c07b19 80
eb465b32 81=item B<not>
e3c07b19 82
83Equivalent of 'not C<$value>'.
84
85=back
86
55a9d564 87=head1 METHODS
88
89=over 4
90
91=item B<meta>
92
55a9d564 93=item B<has_method_provider>
94
95=item B<method_provider>
96
97=back
98
e3c07b19 99=head1 BUGS
100
d4048ef3 101See L<Moose/BUGS> for details on reporting bugs.
e3c07b19 102
103=head1 AUTHOR
104
105Jason May
106
107=head1 COPYRIGHT AND LICENSE
108
109Copyright 2007-2009 by Infinity Interactive, Inc.
110
111L<http://www.iinteractive.com>
112
113This library is free software; you can redistribute it and/or modify
114it under the same terms as Perl itself.
115
116=cut