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