Add inling for native Code trait
[gitmo/Moose.git] / lib / Moose / Meta / Attribute / Native / Trait / Bool.pm
CommitLineData
c466e58f 1package Moose::Meta::Attribute::Native::Trait::Bool;
e3c07b19 2use Moose::Role;
e3c07b19 3
b6cca0d5 4our $VERSION = '1.14';
e3c07b19 5$VERSION = eval $VERSION;
6our $AUTHORITY = 'cpan:STEVAN';
7
664e417b 8use Moose::Meta::Method::Accessor::Native::Bool::not;
9use Moose::Meta::Method::Accessor::Native::Bool::set;
10use Moose::Meta::Method::Accessor::Native::Bool::toggle;
11use Moose::Meta::Method::Accessor::Native::Bool::unset;
12
c466e58f 13with 'Moose::Meta::Attribute::Native::Trait';
e3c07b19 14
55a9d564 15sub _default_is { 'rw' }
2e069f5a 16sub _helper_type { 'Bool' }
2edb73d9 17
664e417b 18sub _native_type { 'Bool' }
e3c07b19 19
e3c07b19 20no Moose::Role;
21
e3c07b19 221;
23
24=pod
25
26=head1 NAME
27
2420461c 28Moose::Meta::Attribute::Native::Trait::Bool - Helper trait for Bool attributes
e3c07b19 29
30=head1 SYNOPSIS
31
32 package Room;
33 use Moose;
e3c07b19 34
35 has 'is_lit' => (
9610c1d2 36 traits => ['Bool'],
e3c07b19 37 is => 'rw',
38 isa => 'Bool',
2edb73d9 39 default => 0,
5f3663b2 40 handles => {
41 illuminate => 'set',
42 darken => 'unset',
43 flip_switch => 'toggle',
44 is_dark => 'not',
9610c1d2 45 },
e3c07b19 46 );
47
48 my $room = Room->new();
49 $room->illuminate; # same as $room->is_lit(1);
50 $room->darken; # same as $room->is_lit(0);
51 $room->flip_switch; # same as $room->is_lit(not $room->is_lit);
52 return $room->is_dark; # same as !$room->is_lit
53
54=head1 DESCRIPTION
55
56This provides a simple boolean attribute, which supports most of the
57basic math operations.
58
e3c07b19 59=head1 PROVIDED METHODS
60
55a9d564 61These methods are implemented in
62L<Moose::Meta::Attribute::Native::MethodProvider::Bool>. It is important to
63note that all those methods do in place modification of the value stored in
64the attribute.
e3c07b19 65
66=over 4
67
eb465b32 68=item B<set>
e3c07b19 69
70Sets the value to C<1>.
71
eb465b32 72=item B<unset>
e3c07b19 73
74Set the value to C<0>.
75
eb465b32 76=item B<toggle>
e3c07b19 77
157e0475 78Toggles the value. If it's true, set to false, and vice versa.
e3c07b19 79
eb465b32 80=item B<not>
e3c07b19 81
82Equivalent of 'not C<$value>'.
83
84=back
85
55a9d564 86=head1 METHODS
87
88=over 4
89
90=item B<meta>
91
55a9d564 92=item B<has_method_provider>
93
94=item B<method_provider>
95
96=back
97
e3c07b19 98=head1 BUGS
99
d4048ef3 100See L<Moose/BUGS> for details on reporting bugs.
e3c07b19 101
102=head1 AUTHOR
103
104Jason May
105
106=head1 COPYRIGHT AND LICENSE
107
108Copyright 2007-2009 by Infinity Interactive, Inc.
109
110L<http://www.iinteractive.com>
111
112This library is free software; you can redistribute it and/or modify
113it under the same terms as Perl itself.
114
115=cut