The synopsis was a little goofy
[gitmo/MooseX-AttributeHelpers.git] / lib / MooseX / AttributeHelpers / Bool.pm
CommitLineData
063fae5e 1package MooseX::AttributeHelpers::Bool;
2use Moose;
3use MooseX::AttributeHelpers::MethodProvider::Bool;
4
7a93b96e 5our $VERSION = '0.14';
38430345 6$VERSION = eval $VERSION;
063fae5e 7our $AUTHORITY = 'cpan:STEVAN';
8
9extends 'MooseX::AttributeHelpers::Base';
10
11sub helper_type { 'Bool' }
12
13# NOTE:
14# we don't use the method provider for this
15# module since many of the names of the provied
16# methods would conflict with keywords
17# - SL
18
19has '+method_provider' => (
20 default => 'MooseX::AttributeHelpers::MethodProvider::Bool'
21);
22
23no Moose;
24
25# register the alias ...
26package # hide me from search.cpan.org
27 Moose::Meta::Attribute::Custom::Bool;
28sub register_implementation { 'MooseX::AttributeHelpers::Bool' }
29
301;
31
32=pod
33
34=head1 NAME
35
36MooseX::AttributeHelpers::Bool
37
38=head1 SYNOPSIS
39
40 package Room;
41 use Moose;
42 use MooseX::AttributeHelpers;
43
44 has 'is_lit' => (
45 metaclass => 'Bool',
46 is => 'rw',
823a6441 47 isa => 'Bool',
063fae5e 48 default => sub { 0 },
49 provides => {
50 set => 'illuminate',
51 unset => 'darken',
52 toggle => 'flip_switch',
53 not => 'is_dark'
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
74=item B<helper_type>
75
76=item B<method_constructors>
77
c6f9edf8 78=item B<has_method_provider>
79
80=item B<method_provider>
81
063fae5e 82=back
83
84=head1 PROVIDED METHODS
85
86It is important to note that all those methods do in place
87modification of the value stored in the attribute.
88
89=over 4
90
91=item I<set>
92
93Sets the value to C<1>.
94
95=item I<unset>
96
97Set the value to C<0>.
98
99=item I<toggle>
100
101Toggle the value. If it's true, set to false, and vice versa.
102
103=item I<not>
104
105Equivalent of 'not C<$value>'.
106
107=back
108
109=head1 BUGS
110
111All complex software has bugs lurking in it, and this module is no
112exception. If you find a bug please either email me, or add the bug
113to cpan-RT.
114
115=head1 AUTHOR
116
117Jason May
118
119=head1 COPYRIGHT AND LICENSE
120
121Copyright 2007-2008 by Infinity Interactive, Inc.
122
123L<http://www.iinteractive.com>
124
125This library is free software; you can redistribute it and/or modify
126it under the same terms as Perl itself.
127
128=cut