1 package Moose::AttributeHelpers::Trait::Bool;
3 use Moose::AttributeHelpers::MethodProvider::Bool;
6 $VERSION = eval $VERSION;
7 our $AUTHORITY = 'cpan:STEVAN';
9 with 'Moose::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 => 'Moose::AttributeHelpers::MethodProvider::Bool'
26 before 'process_options_for_handles' => 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;
37 # register the alias ...
38 package # hide me from search.cpan.org
39 Moose::Meta::Attribute::Custom::Trait::Bool;
40 sub register_implementation { 'Moose::AttributeHelpers::Trait::Bool' }
48 Moose::AttributeHelpers::Bool
54 use Moose::AttributeHelpers;
64 toggle => 'flip_switch',
69 my $room = Room->new();
70 $room->illuminate; # same as $room->is_lit(1);
71 $room->darken; # same as $room->is_lit(0);
72 $room->flip_switch; # same as $room->is_lit(not $room->is_lit);
73 return $room->is_dark; # same as !$room->is_lit
77 This provides a simple boolean attribute, which supports most of the
78 basic math operations.
88 =item B<method_constructors>
90 =item B<has_method_provider>
92 =item B<method_provider>
96 =head1 PROVIDED METHODS
98 It is important to note that all those methods do in place
99 modification of the value stored in the attribute.
105 Sets the value to C<1>.
109 Set the value to C<0>.
113 Toggle the value. If it's true, set to false, and vice versa.
117 Equivalent of 'not C<$value>'.
123 All complex software has bugs lurking in it, and this module is no
124 exception. If you find a bug please either email me, or add the bug
131 =head1 COPYRIGHT AND LICENSE
133 Copyright 2007-2009 by Infinity Interactive, Inc.
135 L<http://www.iinteractive.com>
137 This library is free software; you can redistribute it and/or modify
138 it under the same terms as Perl itself.