Checking in changes prior to tagging of version 0.93. Changelog diff is:
[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
6d0815b5 5our $VERSION = '0.93';
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
a65d8455 14# NOTE: we don't use the method provider for this module since many of
15# the names of the provided methods would conflict with keywords - SL
e3c07b19 16
17has 'method_provider' => (
18 is => 'ro',
19 isa => 'ClassName',
20 predicate => 'has_method_provider',
c466e58f 21 default => 'Moose::Meta::Attribute::Native::MethodProvider::Bool'
e3c07b19 22);
23
e3c07b19 24no Moose::Role;
25
e3c07b19 261;
27
28=pod
29
30=head1 NAME
31
2420461c 32Moose::Meta::Attribute::Native::Trait::Bool - Helper trait for Bool attributes
e3c07b19 33
34=head1 SYNOPSIS
35
36 package Room;
37 use Moose;
e3c07b19 38
39 has 'is_lit' => (
9610c1d2 40 traits => ['Bool'],
e3c07b19 41 is => 'rw',
42 isa => 'Bool',
2edb73d9 43 default => 0,
5f3663b2 44 handles => {
45 illuminate => 'set',
46 darken => 'unset',
47 flip_switch => 'toggle',
48 is_dark => 'not',
9610c1d2 49 },
e3c07b19 50 );
51
52 my $room = Room->new();
53 $room->illuminate; # same as $room->is_lit(1);
54 $room->darken; # same as $room->is_lit(0);
55 $room->flip_switch; # same as $room->is_lit(not $room->is_lit);
56 return $room->is_dark; # same as !$room->is_lit
57
58=head1 DESCRIPTION
59
60This provides a simple boolean attribute, which supports most of the
61basic math operations.
62
e3c07b19 63=head1 PROVIDED METHODS
64
55a9d564 65These methods are implemented in
66L<Moose::Meta::Attribute::Native::MethodProvider::Bool>. It is important to
67note that all those methods do in place modification of the value stored in
68the attribute.
e3c07b19 69
70=over 4
71
eb465b32 72=item B<set>
e3c07b19 73
74Sets the value to C<1>.
75
eb465b32 76=item B<unset>
e3c07b19 77
78Set the value to C<0>.
79
eb465b32 80=item B<toggle>
e3c07b19 81
157e0475 82Toggles the value. If it's true, set to false, and vice versa.
e3c07b19 83
eb465b32 84=item B<not>
e3c07b19 85
86Equivalent of 'not C<$value>'.
87
88=back
89
55a9d564 90=head1 METHODS
91
92=over 4
93
94=item B<meta>
95
55a9d564 96=item B<has_method_provider>
97
98=item B<method_provider>
99
100=back
101
e3c07b19 102=head1 BUGS
103
104All complex software has bugs lurking in it, and this module is no
105exception. If you find a bug please either email me, or add the bug
106to cpan-RT.
107
108=head1 AUTHOR
109
110Jason May
111
112=head1 COPYRIGHT AND LICENSE
113
114Copyright 2007-2009 by Infinity Interactive, Inc.
115
116L<http://www.iinteractive.com>
117
118This library is free software; you can redistribute it and/or modify
119it under the same terms as Perl itself.
120
121=cut