1 package MooseX::AttributeHelpers::Trait::Bool;
3 use MooseX::AttributeHelpers::MethodProvider::Bool;
6 $VERSION = eval $VERSION;
7 our $AUTHORITY = 'cpan:STEVAN';
9 with 'MooseX::AttributeHelpers::Trait::Base';
11 sub helper_type { 'Bool' }
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
19 has 'method_provider' => (
22 predicate => 'has_method_provider',
23 default => 'MooseX::AttributeHelpers::MethodProvider::Bool'
26 before 'process_options_for_provides' => sub {
27 my ($self, $options, $name) = @_;
29 # Set some default attribute options here unless already defined
30 if ((my $type = $self->helper_type) && !exists $options->{isa}){
31 $options->{isa} = $type;
43 MooseX::AttributeHelpers::Bool
49 use MooseX::AttributeHelpers;
59 toggle => 'flip_switch',
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
72 This provides a simple boolean attribute, which supports most of the
73 basic math operations.
83 =item B<method_constructors>
85 =item B<has_method_provider>
87 =item B<method_provider>
91 =head1 PROVIDED METHODS
93 It is important to note that all those methods do in place
94 modification of the value stored in the attribute.
100 Sets the value to C<1>.
104 Set the value to C<0>.
108 Toggle the value. If it's true, set to false, and vice versa.
112 Equivalent of 'not C<$value>'.
118 All complex software has bugs lurking in it, and this module is no
119 exception. If you find a bug please either email me, or add the bug
126 =head1 COPYRIGHT AND LICENSE
128 Copyright 2007-2009 by Infinity Interactive, Inc.
130 L<http://www.iinteractive.com>
132 This library is free software; you can redistribute it and/or modify
133 it under the same terms as Perl itself.