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