line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MooseX::AttributeHelpers::Trait::Bool; |
2
|
22
|
|
|
22
|
|
8672
|
use Moose::Role; |
|
22
|
|
|
|
|
68707
|
|
|
22
|
|
|
|
|
91
|
|
3
|
22
|
|
|
22
|
|
90510
|
use MooseX::AttributeHelpers::MethodProvider::Bool; |
|
22
|
|
|
|
|
42
|
|
|
22
|
|
|
|
|
2403
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.25'; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
with 'MooseX::AttributeHelpers::Trait::Base'; |
8
|
|
|
|
|
|
|
|
9
|
4
|
|
|
4
|
1
|
35
|
sub helper_type { 'Bool' } |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# NOTE: |
12
|
|
|
|
|
|
|
# we don't use the method provider for this |
13
|
|
|
|
|
|
|
# module since many of the names of the provied |
14
|
|
|
|
|
|
|
# methods would conflict with keywords |
15
|
|
|
|
|
|
|
# - SL |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
has 'method_provider' => ( |
18
|
|
|
|
|
|
|
is => 'ro', |
19
|
|
|
|
|
|
|
isa => 'ClassName', |
20
|
|
|
|
|
|
|
predicate => 'has_method_provider', |
21
|
|
|
|
|
|
|
default => 'MooseX::AttributeHelpers::MethodProvider::Bool' |
22
|
|
|
|
|
|
|
); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
before 'process_options_for_provides' => sub { |
25
|
|
|
|
|
|
|
my ($self, $options, $name) = @_; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# Set some default attribute options here unless already defined |
28
|
|
|
|
|
|
|
if ((my $type = $self->helper_type) && !exists $options->{isa}){ |
29
|
|
|
|
|
|
|
$options->{isa} = $type; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
}; |
32
|
|
|
|
|
|
|
|
33
|
22
|
|
|
22
|
|
121
|
no Moose::Role; |
|
22
|
|
|
|
|
24
|
|
|
22
|
|
|
|
|
79
|
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
1; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
__END__ |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=pod |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=encoding UTF-8 |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 NAME |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
MooseX::AttributeHelpers::Trait::Bool |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head1 VERSION |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
version 0.25 |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head1 SYNOPSIS |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
package Room; |
54
|
|
|
|
|
|
|
use Moose; |
55
|
|
|
|
|
|
|
use MooseX::AttributeHelpers; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
has 'is_lit' => ( |
58
|
|
|
|
|
|
|
metaclass => 'Bool', |
59
|
|
|
|
|
|
|
is => 'rw', |
60
|
|
|
|
|
|
|
isa => 'Bool', |
61
|
|
|
|
|
|
|
default => sub { 0 }, |
62
|
|
|
|
|
|
|
provides => { |
63
|
|
|
|
|
|
|
set => 'illuminate', |
64
|
|
|
|
|
|
|
unset => 'darken', |
65
|
|
|
|
|
|
|
toggle => 'flip_switch', |
66
|
|
|
|
|
|
|
not => 'is_dark' |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
); |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
my $room = Room->new(); |
71
|
|
|
|
|
|
|
$room->illuminate; # same as $room->is_lit(1); |
72
|
|
|
|
|
|
|
$room->darken; # same as $room->is_lit(0); |
73
|
|
|
|
|
|
|
$room->flip_switch; # same as $room->is_lit(not $room->is_lit); |
74
|
|
|
|
|
|
|
return $room->is_dark; # same as !$room->is_lit |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head1 DESCRIPTION |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
This provides a simple boolean attribute, which supports most of the |
79
|
|
|
|
|
|
|
basic math operations. |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 METHODS |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=over 4 |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=item B<meta> |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=item B<helper_type> |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=item B<method_constructors> |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=item B<has_method_provider> |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=item B<method_provider> |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=back |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 PROVIDED METHODS |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
It is important to note that all those methods do in place |
100
|
|
|
|
|
|
|
modification of the value stored in the attribute. |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=over 4 |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=item I<set> |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Sets the value to C<1>. |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=item I<unset> |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Set the value to C<0>. |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=item I<toggle> |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Toggle the value. If it's true, set to false, and vice versa. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=item I<not> |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
Equivalent of 'not C<$value>'. |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=back |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head1 SUPPORT |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Bugs may be submitted through L<the RT bug tracker|https://rt.cpan.org/Public/Dist/Display.html?Name=MooseX-AttributeHelpers> |
125
|
|
|
|
|
|
|
(or L<bug-MooseX-AttributeHelpers@rt.cpan.org|mailto:bug-MooseX-AttributeHelpers@rt.cpan.org>). |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
There is also a mailing list available for users of this distribution, at |
128
|
|
|
|
|
|
|
L<http://lists.perl.org/list/moose.html>. |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
There is also an irc channel available for users of this distribution, at |
131
|
|
|
|
|
|
|
L<C<#moose> on C<irc.perl.org>|irc://irc.perl.org/#moose>. |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head1 AUTHOR |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
Stevan Little <stevan@iinteractive.com> |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
Jason May |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
This software is copyright (c) 2007 by Stevan Little and Infinity Interactive, Inc. |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
144
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=cut |