1 package MooseX::AttributeHelpers::Bool;
3 use MooseX::AttributeHelpers::MethodProvider::Bool;
6 $VERSION = eval $VERSION;
7 our $AUTHORITY = 'cpan:STEVAN';
9 extends 'MooseX::AttributeHelpers::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' => (
20 default => 'MooseX::AttributeHelpers::MethodProvider::Bool'
23 before 'process_options_for_provides' => sub {
24 my ($self, $options, $name) = @_;
26 # Set some default attribute options here unless already defined
27 if ((my $type = $self->helper_type) && !exists $options->{isa}){
28 $options->{isa} = $type;
34 # register the alias ...
35 package # hide me from search.cpan.org
36 Moose::Meta::Attribute::Custom::Bool;
37 sub register_implementation { 'MooseX::AttributeHelpers::Bool' }
45 MooseX::AttributeHelpers::Bool
51 use MooseX::AttributeHelpers;
61 toggle => 'flip_switch',
66 my $room = Room->new();
67 $room->illuminate; # same as $room->is_lit(1);
68 $room->darken; # same as $room->is_lit(0);
69 $room->flip_switch; # same as $room->is_lit(not $room->is_lit);
70 return $room->is_dark; # same as !$room->is_lit
74 This provides a simple boolean attribute, which supports most of the
75 basic math operations.
85 =item B<method_constructors>
87 =item B<has_method_provider>
89 =item B<method_provider>
93 =head1 PROVIDED METHODS
95 It is important to note that all those methods do in place
96 modification of the value stored in the attribute.
102 Sets the value to C<1>.
106 Set the value to C<0>.
110 Toggle the value. If it's true, set to false, and vice versa.
114 Equivalent of 'not C<$value>'.
120 All complex software has bugs lurking in it, and this module is no
121 exception. If you find a bug please either email me, or add the bug
128 =head1 COPYRIGHT AND LICENSE
130 Copyright 2007-2008 by Infinity Interactive, Inc.
132 L<http://www.iinteractive.com>
134 This library is free software; you can redistribute it and/or modify
135 it under the same terms as Perl itself.