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