line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MooX::ClassAttribute::HandleMoose; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
56
|
use 5.008; |
|
2
|
|
|
|
|
123
|
|
|
2
|
|
|
|
|
90
|
|
4
|
2
|
|
|
2
|
|
13
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
82
|
|
5
|
2
|
|
|
2
|
|
21
|
use warnings; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
133
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
BEGIN { |
8
|
2
|
|
|
2
|
|
4
|
$MooX::ClassAttribute::HandleMoose::AUTHORITY = 'cpan:TOBYINK'; |
9
|
2
|
|
|
|
|
1593
|
$MooX::ClassAttribute::HandleMoose::VERSION = '0.010'; |
10
|
|
|
|
|
|
|
} |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
{ |
13
|
|
|
|
|
|
|
package MooX::ClassAttribute; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our %ROLE; |
16
|
|
|
|
|
|
|
our %CLASS; |
17
|
|
|
|
|
|
|
our %ATTRIBUTES; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
my $warning; |
20
|
|
|
|
|
|
|
sub _on_inflation |
21
|
|
|
|
|
|
|
{ |
22
|
14
|
|
|
14
|
|
34
|
my ($me, $target, $args) = @_; |
23
|
14
|
|
|
|
|
26
|
my $meta = $args->[0]; |
24
|
|
|
|
|
|
|
|
25
|
14
|
|
|
|
|
109
|
eval { require MooseX::ClassAttribute } |
26
|
14
|
0
|
|
|
|
28
|
or do { carp <<WARNING unless $warning++; return }; |
|
0
|
50
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
27
|
|
|
|
|
|
|
*** |
28
|
|
|
|
|
|
|
*** MooX::ClassAttribute and Moose, but MooseX::ClassAttribute is not |
29
|
|
|
|
|
|
|
*** available. It is strongly recommended that you install this module. |
30
|
|
|
|
|
|
|
*** |
31
|
|
|
|
|
|
|
WARNING |
32
|
|
|
|
|
|
|
|
33
|
14
|
|
|
|
|
25
|
1;#meh |
34
|
14
|
|
|
|
|
72
|
require Moose::Util::MetaRole; |
35
|
14
|
100
|
|
|
|
94
|
if ( is_role($meta->name) ) |
36
|
|
|
|
|
|
|
{ |
37
|
2
|
|
|
|
|
22
|
$meta = Moose::Util::MetaRole::apply_metaroles( |
38
|
|
|
|
|
|
|
for => $meta->name, |
39
|
|
|
|
|
|
|
role_metaroles => { |
40
|
|
|
|
|
|
|
role => ['MooseX::ClassAttribute::Trait::Role'], |
41
|
|
|
|
|
|
|
application_to_class => ['MooseX::ClassAttribute::Trait::Application::ToClass'], |
42
|
|
|
|
|
|
|
application_to_role => ['MooseX::ClassAttribute::Trait::Application::ToRole'], |
43
|
|
|
|
|
|
|
}, |
44
|
|
|
|
|
|
|
); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
else |
47
|
|
|
|
|
|
|
{ |
48
|
12
|
|
|
|
|
126
|
$meta = Moose::Util::MetaRole::apply_metaroles( |
49
|
|
|
|
|
|
|
for => $meta->name, |
50
|
|
|
|
|
|
|
class_metaroles => { |
51
|
|
|
|
|
|
|
class => ['MooseX::ClassAttribute::Trait::Class'] #,'MooseX::ClassAttribute::Hack'] |
52
|
|
|
|
|
|
|
}, |
53
|
|
|
|
|
|
|
); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
14
|
|
50
|
|
|
742088
|
my $attrs = $ATTRIBUTES{$target} || []; |
57
|
14
|
|
|
|
|
70
|
for (my $i = 0; $i < @$attrs; $i+=2) |
58
|
|
|
|
|
|
|
{ |
59
|
14
|
|
|
|
|
42
|
my $name = $attrs->[$i+0]; |
60
|
14
|
|
|
|
|
32
|
my $spec = $attrs->[$i+1]; |
61
|
14
|
|
|
|
|
81
|
MooseX::ClassAttribute::class_has( |
62
|
|
|
|
|
|
|
$meta, |
63
|
|
|
|
|
|
|
$name, |
64
|
|
|
|
|
|
|
$me->_sanitize_spec($name, $spec), |
65
|
|
|
|
|
|
|
); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
14
|
|
|
|
|
65276
|
$args->[0] = $meta; # return new $meta |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
my %ok_options = map { ;$_=>1 } qw( |
72
|
|
|
|
|
|
|
is reader writer accessor clearer predicate handles |
73
|
|
|
|
|
|
|
required isa does coerce trigger |
74
|
|
|
|
|
|
|
default builder lazy_build lazy |
75
|
|
|
|
|
|
|
documentation |
76
|
|
|
|
|
|
|
); |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub _sanitize_spec |
79
|
|
|
|
|
|
|
{ |
80
|
14
|
|
|
14
|
|
32
|
my ($me, $name, $spec) = @_; |
81
|
14
|
|
|
|
|
126
|
my %spec = %$spec; |
82
|
|
|
|
|
|
|
|
83
|
14
|
|
|
|
|
42
|
my $TYPE_MAP = \%Moo::HandleMoose::TYPE_MAP; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
# Stolen from Moo::HandleMoose |
86
|
14
|
50
|
33
|
|
|
118
|
$spec{is} = 'ro' if $spec{is} eq 'lazy' || $spec{is} eq 'rwp'; |
87
|
14
|
50
|
|
|
|
79
|
if (my $isa = $spec{isa}) { |
|
|
50
|
|
|
|
|
|
88
|
0
|
|
|
|
|
0
|
my $tc = $spec{isa} = do { |
89
|
0
|
0
|
|
|
|
0
|
if (my $mapped = $TYPE_MAP->{$isa}) { |
90
|
0
|
|
|
|
|
0
|
$mapped->(); |
91
|
|
|
|
|
|
|
} else { |
92
|
|
|
|
|
|
|
Moose::Meta::TypeConstraint->new( |
93
|
0
|
|
|
0
|
|
0
|
constraint => sub { eval { &$isa; 1 } } |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
94
|
0
|
|
|
|
|
0
|
); |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
}; |
97
|
0
|
0
|
|
|
|
0
|
if (my $coerce = $spec{coerce}) { |
98
|
0
|
|
|
|
|
0
|
$tc |
99
|
|
|
|
|
|
|
-> coercion(Moose::Meta::TypeCoercion->new) |
100
|
|
|
|
|
|
|
-> _compiled_type_coercion($coerce); |
101
|
0
|
|
|
|
|
0
|
$spec{coerce} = 1; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
elsif (my $coerce = $spec{coerce}) { |
105
|
0
|
|
|
|
|
0
|
my $attr = perlstring($name); |
106
|
|
|
|
|
|
|
my $tc = Moose::Meta::TypeConstraint->new( |
107
|
0
|
|
|
0
|
|
0
|
constraint => sub { die "This is not going to work" }, |
108
|
0
|
|
|
0
|
|
0
|
inlined => sub { 'my $r = $_[42]{'.$attr.'}; $_[42]{'.$attr.'} = 1; $r' }, |
109
|
0
|
|
|
|
|
0
|
); |
110
|
0
|
|
|
|
|
0
|
$tc |
111
|
|
|
|
|
|
|
-> coercion(Moose::Meta::TypeCoercion->new) |
112
|
|
|
|
|
|
|
-> _compiled_type_coercion($coerce); |
113
|
0
|
|
|
|
|
0
|
$spec{isa} = $tc; |
114
|
0
|
|
|
|
|
0
|
$spec{coerce} = 1; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
14
|
|
|
|
|
23
|
my @return; |
118
|
14
|
|
|
|
|
43
|
for my $key (%spec) |
119
|
|
|
|
|
|
|
{ |
120
|
98
|
100
|
|
|
|
238
|
next unless $ok_options{$key}; |
121
|
35
|
|
|
|
|
75
|
push @return, $key, $spec->{$key}; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
return ( |
124
|
14
|
|
|
|
|
147
|
@return, |
125
|
|
|
|
|
|
|
definition_context => { package => __PACKAGE__ }, |
126
|
|
|
|
|
|
|
); |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
## This doesn't actually seem needed any more... |
131
|
|
|
|
|
|
|
#{ |
132
|
|
|
|
|
|
|
# package |
133
|
|
|
|
|
|
|
# MooseX::ClassAttribute::Hack; |
134
|
|
|
|
|
|
|
# use Moo::Role; |
135
|
|
|
|
|
|
|
# around _post_add_class_attribute => sub { |
136
|
|
|
|
|
|
|
# my $orig = shift; |
137
|
|
|
|
|
|
|
# my $self = shift; |
138
|
|
|
|
|
|
|
# return if $self->definition_context->{package} eq 'MooX::ClassAttribute'; |
139
|
|
|
|
|
|
|
# $self->$orig(@_); |
140
|
|
|
|
|
|
|
# }; |
141
|
|
|
|
|
|
|
#} |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
1; |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
__END__ |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=head1 NAME |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
MooX::ClassAttribute::HandleMoose - Moose inflation stuff |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=head1 DESCRIPTION |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
For an idea of how this works, see the very fine documentation for |
154
|
|
|
|
|
|
|
L<Moo::HandleMoose>. |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head1 BUGS |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
Please report any bugs to |
159
|
|
|
|
|
|
|
L<http://rt.cpan.org/Dist/Display.html?Queue=MooX-ClassAttribute>. |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head1 SEE ALSO |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
L<Moo::HandleMoose>, |
164
|
|
|
|
|
|
|
L<MooX::ClassAttribute>. |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head1 AUTHOR |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
Toby Inkster E<lt>tobyink@cpan.orgE<gt>. |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENCE |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
This software is copyright (c) 2013 by Toby Inkster. |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
175
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=head1 DISCLAIMER OF WARRANTIES |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED |
180
|
|
|
|
|
|
|
WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF |
181
|
|
|
|
|
|
|
MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
182
|
|
|
|
|
|
|
|