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