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