line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MooseX::AlwaysCoerce; |
2
|
|
|
|
|
|
|
{ |
3
|
|
|
|
|
|
|
$MooseX::AlwaysCoerce::VERSION = '0.21'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
# git description: v0.20-7-gd590377 |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
BEGIN { |
8
|
3
|
|
|
3
|
|
920574
|
$MooseX::AlwaysCoerce::AUTHORITY = 'cpan:RKITOVER'; |
9
|
|
|
|
|
|
|
} |
10
|
|
|
|
|
|
|
# ABSTRACT: Automatically enable coercions for Moose attributes |
11
|
|
|
|
|
|
|
|
12
|
3
|
|
|
3
|
|
24
|
use strict; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
83
|
|
13
|
3
|
|
|
3
|
|
11
|
use warnings; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
78
|
|
14
|
|
|
|
|
|
|
|
15
|
3
|
|
|
3
|
|
758
|
use namespace::autoclean 0.12; |
|
3
|
|
|
|
|
1985
|
|
|
3
|
|
|
|
|
14
|
|
16
|
3
|
|
|
3
|
|
134
|
use Moose (); |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
41
|
|
17
|
3
|
|
|
3
|
|
771
|
use MooseX::ClassAttribute 0.24 (); |
|
3
|
|
|
|
|
111776
|
|
|
3
|
|
|
|
|
56
|
|
18
|
3
|
|
|
3
|
|
16
|
use Moose::Exporter; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
11
|
|
19
|
3
|
|
|
3
|
|
110
|
use Moose::Util::MetaRole; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
37
|
|
20
|
3
|
|
|
3
|
|
12
|
use Carp; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
323
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
Moose::Exporter->setup_import_methods; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
{ |
26
|
|
|
|
|
|
|
package MooseX::AlwaysCoerce::Role::Meta::Attribute; |
27
|
|
|
|
|
|
|
{ |
28
|
|
|
|
|
|
|
$MooseX::AlwaysCoerce::Role::Meta::Attribute::VERSION = '0.21'; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
# git description: v0.20-7-gd590377 |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
BEGIN { |
33
|
3
|
|
|
3
|
|
35
|
$MooseX::AlwaysCoerce::Role::Meta::Attribute::AUTHORITY = 'cpan:RKITOVER'; |
34
|
|
|
|
|
|
|
} |
35
|
3
|
|
|
3
|
|
11
|
use namespace::autoclean; |
|
3
|
|
|
|
|
20
|
|
|
3
|
|
|
|
|
11
|
|
36
|
3
|
|
|
3
|
|
131
|
use Moose::Role; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
12
|
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
around should_coerce => sub { |
39
|
|
|
|
|
|
|
my $orig = shift; |
40
|
|
|
|
|
|
|
my $self = shift; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
my $current_val = $self->$orig(@_); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
return $current_val if defined $current_val; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
return 1 if $self->type_constraint && $self->type_constraint->has_coercion; |
47
|
|
|
|
|
|
|
return 0; |
48
|
|
|
|
|
|
|
}; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
package MooseX::AlwaysCoerce::Role::Meta::Class; |
51
|
|
|
|
|
|
|
{ |
52
|
|
|
|
|
|
|
$MooseX::AlwaysCoerce::Role::Meta::Class::VERSION = '0.21'; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
# git description: v0.20-7-gd590377 |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
BEGIN { |
57
|
3
|
|
|
3
|
|
10265
|
$MooseX::AlwaysCoerce::Role::Meta::Class::AUTHORITY = 'cpan:RKITOVER'; |
58
|
|
|
|
|
|
|
} |
59
|
3
|
|
|
3
|
|
15
|
use namespace::autoclean; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
10
|
|
60
|
3
|
|
|
3
|
|
121
|
use Moose::Role; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
9
|
|
61
|
3
|
|
|
3
|
|
9531
|
use Moose::Util::TypeConstraints; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
18
|
|
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
around add_class_attribute => sub { |
64
|
|
|
|
|
|
|
my $next = shift; |
65
|
|
|
|
|
|
|
my $self = shift; |
66
|
|
|
|
|
|
|
my ($what, %opts) = @_; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
if (exists $opts{isa}) { |
69
|
|
|
|
|
|
|
my $type = Moose::Util::TypeConstraints::find_or_parse_type_constraint($opts{isa}); |
70
|
|
|
|
|
|
|
$opts{coerce} = 1 if not exists $opts{coerce} and $type->has_coercion; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
$self->$next($what, %opts); |
74
|
|
|
|
|
|
|
}; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
my (undef, undef, $init_meta) = Moose::Exporter->build_import_methods( |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
install => [ qw(import unimport) ], |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
class_metaroles => { |
82
|
|
|
|
|
|
|
attribute => ['MooseX::AlwaysCoerce::Role::Meta::Attribute'], |
83
|
|
|
|
|
|
|
class => ['MooseX::AlwaysCoerce::Role::Meta::Class'], |
84
|
|
|
|
|
|
|
}, |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
role_metaroles => { |
87
|
|
|
|
|
|
|
(Moose->VERSION >= 1.9900 |
88
|
|
|
|
|
|
|
? (applied_attribute => ['MooseX::AlwaysCoerce::Role::Meta::Attribute']) |
89
|
|
|
|
|
|
|
: ()), |
90
|
|
|
|
|
|
|
role => ['MooseX::AlwaysCoerce::Role::Meta::Class'], |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
); |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub init_meta { |
95
|
3
|
|
|
3
|
0
|
173
|
my ($class, %options) = @_; |
96
|
3
|
|
|
|
|
3
|
my $for_class = $options{for_class}; |
97
|
|
|
|
|
|
|
|
98
|
3
|
|
|
|
|
14
|
MooseX::ClassAttribute->import({ into => $for_class }); |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
# call generated method to do the rest of the work. |
101
|
3
|
|
|
|
|
387013
|
goto $init_meta; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
1; |
105
|
|
|
|
|
|
|
# vim:et sts=4 sw=4 tw=0: |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
__END__ |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=pod |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=encoding UTF-8 |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=for :stopwords Rafael Kitover <rkitover@cpan.org> Jesse Luehrs Karen Etheridge Michael G. |
114
|
|
|
|
|
|
|
Schwern coercions AnnoCPAN Rolsky |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head1 NAME |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
MooseX::AlwaysCoerce - Automatically enable coercions for Moose attributes |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head1 VERSION |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
version 0.21 |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head1 SYNOPSIS |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
package MyClass; |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
use Moose; |
129
|
|
|
|
|
|
|
use MooseX::AlwaysCoerce; |
130
|
|
|
|
|
|
|
use MyTypeLib 'SomeType'; |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
has foo => (is => 'rw', isa => SomeType); # coerce => 1 automatically added |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
# same, MooseX::ClassAttribute is automatically applied |
135
|
|
|
|
|
|
|
class_has bar => (is => 'rw', isa => SomeType); |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head1 DESCRIPTION |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
Have you ever spent an hour or more trying to figure out "Hey, why did my |
140
|
|
|
|
|
|
|
coercion not run?" only to find out that you forgot C<< coerce => 1 >> ? |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
Just load this module in your L<Moose> class and C<< coerce => 1 >> will be |
143
|
|
|
|
|
|
|
enabled for every attribute and class attribute automatically. |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
Use C<< coerce => 0 >> to disable a coercion explicitly. |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=for Pod::Coverage init_meta |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head1 BUGS |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
Please report any bugs or feature requests to C<bug-moosex-alwayscoerce at rt.cpan.org>, or through |
152
|
|
|
|
|
|
|
the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=MooseX-AlwaysCoerce>. I will be notified, and then you'll |
153
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=head1 SUPPORT |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
You can find more information at: |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=over 4 |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=MooseX-AlwaysCoerce> |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
L<http://annocpan.org/dist/MooseX-AlwaysCoerce> |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=item * CPAN Ratings |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
L<http://cpanratings.perl.org/d/MooseX-AlwaysCoerce> |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=item * Search CPAN |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
L<http://search.cpan.org/dist/MooseX-AlwaysCoerce/> |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=back |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
My own stupidity, for inspiring me to write this module. |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
Dave Rolsky, for telling me how to do it the L<Moose> way. |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=head1 AUTHOR |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
Rafael Kitover <rkitover@cpan.org> |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
This software is copyright (c) 2009 by Rafael Kitover <rkitover@cpan.org>. |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
194
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=head1 CONTRIBUTORS |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=over 4 |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=item * |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
Jesse Luehrs <doy@tozt.net> |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=item * |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
Karen Etheridge <ether@cpan.org> |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=item * |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
Michael G. Schwern <schwern@pobox.com> |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=back |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=cut |