do all the renaming that was discussed
[gitmo/Moose.git] / lib / Moose / Meta / Attribute / Trait / Native / Bool.pm
CommitLineData
a40b446a 1package Moose::Meta::Attribute::Trait::Native::Bool;
e3c07b19 2use Moose::Role;
a40b446a 3use Moose::Meta::Attribute::Trait::Native::MethodProvider::Bool;
e3c07b19 4
96539d20 5our $VERSION = '0.87';
e3c07b19 6$VERSION = eval $VERSION;
7our $AUTHORITY = 'cpan:STEVAN';
8
a40b446a 9with 'Moose::Meta::Attribute::Trait::Native::Base';
e3c07b19 10
2edb73d9 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',
a40b446a 21 default => 'Moose::Meta::Attribute::Trait::Native::MethodProvider::Bool'
e3c07b19 22);
23
e3c07b19 24no Moose::Role;
25
e3c07b19 26package # hide me from search.cpan.org
27 Moose::Meta::Attribute::Custom::Trait::Bool;
a40b446a 28sub register_implementation { 'Moose::Meta::Attribute::Trait::Native::Bool' }
e3c07b19 29
301;
31
32=pod
33
34=head1 NAME
35
a40b446a 36Moose::Meta::Attribute::Trait::Native::Bool
e3c07b19 37
38=head1 SYNOPSIS
39
40 package Room;
41 use Moose;
42 use Moose::AttributeHelpers;
43
44 has 'is_lit' => (
45 metaclass => 'Bool',
46 is => 'rw',
47 isa => 'Bool',
2edb73d9 48 default => 0,
5f3663b2 49 handles => {
50 illuminate => 'set',
51 darken => 'unset',
52 flip_switch => 'toggle',
53 is_dark => 'not',
e3c07b19 54 }
55 );
56
57 my $room = Room->new();
58 $room->illuminate; # same as $room->is_lit(1);
59 $room->darken; # same as $room->is_lit(0);
60 $room->flip_switch; # same as $room->is_lit(not $room->is_lit);
61 return $room->is_dark; # same as !$room->is_lit
62
63=head1 DESCRIPTION
64
65This provides a simple boolean attribute, which supports most of the
66basic math operations.
67
68=head1 METHODS
69
70=over 4
71
72=item B<meta>
73
e3c07b19 74=item B<method_constructors>
75
76=item B<has_method_provider>
77
78=item B<method_provider>
79
80=back
81
82=head1 PROVIDED METHODS
83
84It is important to note that all those methods do in place
85modification of the value stored in the attribute.
86
87=over 4
88
89=item I<set>
90
91Sets the value to C<1>.
92
93=item I<unset>
94
95Set the value to C<0>.
96
97=item I<toggle>
98
99Toggle the value. If it's true, set to false, and vice versa.
100
101=item I<not>
102
103Equivalent of 'not C<$value>'.
104
105=back
106
107=head1 BUGS
108
109All complex software has bugs lurking in it, and this module is no
110exception. If you find a bug please either email me, or add the bug
111to cpan-RT.
112
113=head1 AUTHOR
114
115Jason May
116
117=head1 COPYRIGHT AND LICENSE
118
119Copyright 2007-2009 by Infinity Interactive, Inc.
120
121L<http://www.iinteractive.com>
122
123This library is free software; you can redistribute it and/or modify
124it under the same terms as Perl itself.
125
126=cut