eaa9fd800d2b0077fabcc5fb54f6377fcba88199
[gitmo/Moose.git] / lib / Moose / Meta / Attribute / Native / Trait / Bool.pm
1 package Moose::Meta::Attribute::Native::Trait::Bool;
2 use Moose::Role;
3 use Moose::Meta::Attribute::Native::MethodProvider::Bool;
4
5 our $VERSION = '0.87';
6 $VERSION = eval $VERSION;
7 our $AUTHORITY = 'cpan:STEVAN';
8
9 with 'Moose::Meta::Attribute::Native::Trait';
10
11 sub _default_is  { 'rw' }
12 sub _helper_type { 'Bool' }
13
14 # NOTE: we don't use the method provider for this module since many of
15 # the names of the provided methods would conflict with keywords - SL
16
17 has 'method_provider' => (
18     is        => 'ro',
19     isa       => 'ClassName',
20     predicate => 'has_method_provider',
21     default   => 'Moose::Meta::Attribute::Native::MethodProvider::Bool'
22 );
23
24 no Moose::Role;
25
26 1;
27
28 =pod
29
30 =head1 NAME
31
32 Moose::Meta::Attribute::Native::Trait::Bool
33
34 =head1 SYNOPSIS
35
36   package Room;
37   use Moose;
38   use Moose::AttributeHelpers;
39
40   has 'is_lit' => (
41       traits => ['Bool'],
42       is        => 'rw',
43       isa       => 'Bool',
44       default   => 0,
45       handles   => {
46           illuminate  => 'set',
47           darken      => 'unset',
48           flip_switch => 'toggle',
49           is_dark     => 'not',
50       }
51   );
52
53   my $room = Room->new();
54   $room->illuminate;     # same as $room->is_lit(1);
55   $room->darken;         # same as $room->is_lit(0);
56   $room->flip_switch;    # same as $room->is_lit(not $room->is_lit);
57   return $room->is_dark; # same as !$room->is_lit
58
59 =head1 DESCRIPTION
60
61 This provides a simple boolean attribute, which supports most of the
62 basic math operations.
63
64 =head1 PROVIDED METHODS
65
66 These methods are implemented in
67 L<Moose::Meta::Attribute::Native::MethodProvider::Bool>. It is important to
68 note that all those methods do in place modification of the value stored in
69 the attribute.
70
71 =over 4
72
73 =item I<set>
74
75 Sets the value to C<1>.
76
77 =item I<unset>
78
79 Set the value to C<0>.
80
81 =item I<toggle>
82
83 Toggle the value. If it's true, set to false, and vice versa.
84
85 =item I<not>
86
87 Equivalent of 'not C<$value>'.
88
89 =back
90
91 =head1 METHODS
92
93 =over 4
94
95 =item B<meta>
96
97 =item B<method_constructors>
98
99 =item B<has_method_provider>
100
101 =item B<method_provider>
102
103 =back
104
105 =head1 BUGS
106
107 All complex software has bugs lurking in it, and this module is no
108 exception. If you find a bug please either email me, or add the bug
109 to cpan-RT.
110
111 =head1 AUTHOR
112
113 Jason May
114
115 =head1 COPYRIGHT AND LICENSE
116
117 Copyright 2007-2009 by Infinity Interactive, Inc.
118
119 L<http://www.iinteractive.com>
120
121 This library is free software; you can redistribute it and/or modify
122 it under the same terms as Perl itself.
123
124 =cut