line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MooseX::ClassAttribute::Trait::Attribute; |
2
|
|
|
|
|
|
|
|
3
|
8
|
|
|
8
|
|
27
|
use strict; |
|
8
|
|
|
|
|
8
|
|
|
8
|
|
|
|
|
180
|
|
4
|
8
|
|
|
8
|
|
22
|
use warnings; |
|
8
|
|
|
|
|
8
|
|
|
8
|
|
|
|
|
232
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.29'; |
7
|
|
|
|
|
|
|
|
8
|
8
|
|
|
8
|
|
24
|
use namespace::autoclean; |
|
8
|
|
|
|
|
8
|
|
|
8
|
|
|
|
|
47
|
|
9
|
8
|
|
|
8
|
|
2926
|
use Moose::Role; |
|
8
|
|
|
|
|
21293
|
|
|
8
|
|
|
|
|
27
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# This is the worst role evar! Really, this should be a subclass, |
12
|
|
|
|
|
|
|
# because it overrides a lot of behavior. However, as a subclass it |
13
|
|
|
|
|
|
|
# won't cooperate with _other_ subclasses. |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
around _process_options => sub { |
16
|
|
|
|
|
|
|
my $orig = shift; |
17
|
|
|
|
|
|
|
my $class = shift; |
18
|
|
|
|
|
|
|
my $name = shift; |
19
|
|
|
|
|
|
|
my $options = shift; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
confess 'A class attribute cannot be required' |
22
|
|
|
|
|
|
|
if $options->{required}; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
return $class->$orig( $name, $options ); |
25
|
|
|
|
|
|
|
}; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
after attach_to_class => sub { |
28
|
|
|
|
|
|
|
my $self = shift; |
29
|
|
|
|
|
|
|
my $meta = shift; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
$self->_initialize($meta) |
32
|
|
|
|
|
|
|
unless $self->is_lazy(); |
33
|
|
|
|
|
|
|
}; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
before detach_from_class => sub { |
36
|
|
|
|
|
|
|
my $self = shift; |
37
|
|
|
|
|
|
|
my $meta = shift; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
$self->clear_value($meta); |
40
|
|
|
|
|
|
|
}; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub _initialize { |
43
|
73
|
|
|
73
|
|
455
|
my $self = shift; |
44
|
73
|
|
|
|
|
69
|
my $metaclass = shift; |
45
|
|
|
|
|
|
|
|
46
|
73
|
100
|
|
|
|
217
|
if ( $self->has_default() ) { |
|
|
100
|
|
|
|
|
|
47
|
45
|
|
|
|
|
308
|
$self->set_value( |
48
|
|
|
|
|
|
|
undef, |
49
|
|
|
|
|
|
|
$self->default( $self->associated_class() ) |
50
|
|
|
|
|
|
|
); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
elsif ( $self->has_builder() ) { |
53
|
7
|
|
|
|
|
86
|
$self->set_value( undef, $self->_call_builder( $metaclass->name() ) ); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
around default => sub { |
58
|
|
|
|
|
|
|
my $orig = shift; |
59
|
|
|
|
|
|
|
my $self = shift; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
my $default = $self->$orig(); |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
if ( $self->is_default_a_coderef() && @_ ) { |
64
|
|
|
|
|
|
|
return $default->(@_); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
return $default; |
68
|
|
|
|
|
|
|
}; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
around _call_builder => sub { |
71
|
|
|
|
|
|
|
shift; |
72
|
|
|
|
|
|
|
my $self = shift; |
73
|
|
|
|
|
|
|
my $class = shift; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
my $builder = $self->builder(); |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
return $class->$builder() |
78
|
|
|
|
|
|
|
if $class->can( $self->builder ); |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
confess( "$class does not support builder method '" |
81
|
|
|
|
|
|
|
. $self->builder |
82
|
|
|
|
|
|
|
. "' for attribute '" |
83
|
|
|
|
|
|
|
. $self->name |
84
|
|
|
|
|
|
|
. "'" ); |
85
|
|
|
|
|
|
|
}; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
around set_value => sub { |
88
|
|
|
|
|
|
|
shift; |
89
|
|
|
|
|
|
|
my $self = shift; |
90
|
|
|
|
|
|
|
shift; # ignoring instance or class name |
91
|
|
|
|
|
|
|
my $value = shift; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
$self->associated_class() |
94
|
|
|
|
|
|
|
->set_class_attribute_value( $self->name() => $value ); |
95
|
|
|
|
|
|
|
}; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
around get_value => sub { |
98
|
|
|
|
|
|
|
shift; |
99
|
|
|
|
|
|
|
my $self = shift; |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
return $self->associated_class() |
102
|
|
|
|
|
|
|
->get_class_attribute_value( $self->name() ); |
103
|
|
|
|
|
|
|
}; |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
around has_value => sub { |
106
|
|
|
|
|
|
|
shift; |
107
|
|
|
|
|
|
|
my $self = shift; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
return $self->associated_class() |
110
|
|
|
|
|
|
|
->has_class_attribute_value( $self->name() ); |
111
|
|
|
|
|
|
|
}; |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
around clear_value => sub { |
114
|
|
|
|
|
|
|
shift; |
115
|
|
|
|
|
|
|
my $self = shift; |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
return $self->associated_class() |
118
|
|
|
|
|
|
|
->clear_class_attribute_value( $self->name() ); |
119
|
|
|
|
|
|
|
}; |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
if ( $Moose::VERSION < 1.99 ) { |
122
|
|
|
|
|
|
|
around inline_get => sub { |
123
|
|
|
|
|
|
|
shift; |
124
|
|
|
|
|
|
|
my $self = shift; |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
return $self->associated_class() |
127
|
|
|
|
|
|
|
->_inline_get_class_slot_value( $self->slots() ); |
128
|
|
|
|
|
|
|
}; |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
around inline_set => sub { |
131
|
|
|
|
|
|
|
shift; |
132
|
|
|
|
|
|
|
my $self = shift; |
133
|
|
|
|
|
|
|
shift; |
134
|
|
|
|
|
|
|
my $value = shift; |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
my $meta = $self->associated_class(); |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
my $code |
139
|
|
|
|
|
|
|
= $meta->_inline_set_class_slot_value( $self->slots(), $value ) |
140
|
|
|
|
|
|
|
. ";"; |
141
|
|
|
|
|
|
|
$code .= $meta->_inline_weaken_class_slot_value( |
142
|
|
|
|
|
|
|
$self->slots(), |
143
|
|
|
|
|
|
|
$value |
144
|
|
|
|
|
|
|
) |
145
|
|
|
|
|
|
|
. " if ref $value;" |
146
|
|
|
|
|
|
|
if $self->is_weak_ref(); |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
return $code; |
149
|
|
|
|
|
|
|
}; |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
around inline_has => sub { |
152
|
|
|
|
|
|
|
shift; |
153
|
|
|
|
|
|
|
my $self = shift; |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
return $self->associated_class() |
156
|
|
|
|
|
|
|
->_inline_is_class_slot_initialized( $self->slots() ); |
157
|
|
|
|
|
|
|
}; |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
around inline_clear => sub { |
160
|
|
|
|
|
|
|
shift; |
161
|
|
|
|
|
|
|
my $self = shift; |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
return $self->associated_class() |
164
|
|
|
|
|
|
|
->_inline_deinitialize_class_slot( $self->slots() ); |
165
|
|
|
|
|
|
|
}; |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
else { |
168
|
|
|
|
|
|
|
around _inline_instance_get => sub { |
169
|
|
|
|
|
|
|
shift; |
170
|
|
|
|
|
|
|
my $self = shift; |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
return $self->associated_class() |
173
|
|
|
|
|
|
|
->_inline_get_class_slot_value( $self->slots() ); |
174
|
|
|
|
|
|
|
}; |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
around _inline_instance_set => sub { |
177
|
|
|
|
|
|
|
shift; |
178
|
|
|
|
|
|
|
my $self = shift; |
179
|
|
|
|
|
|
|
shift; |
180
|
|
|
|
|
|
|
my $value = shift; |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
return $self->associated_class() |
183
|
|
|
|
|
|
|
->_inline_set_class_slot_value( $self->slots(), $value ); |
184
|
|
|
|
|
|
|
}; |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
around _inline_instance_has => sub { |
187
|
|
|
|
|
|
|
shift; |
188
|
|
|
|
|
|
|
my $self = shift; |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
return $self->associated_class() |
191
|
|
|
|
|
|
|
->_inline_is_class_slot_initialized( $self->slots() ); |
192
|
|
|
|
|
|
|
}; |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
around _inline_instance_clear => sub { |
195
|
|
|
|
|
|
|
shift; |
196
|
|
|
|
|
|
|
my $self = shift; |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
return $self->associated_class() |
199
|
|
|
|
|
|
|
->_inline_deinitialize_class_slot( $self->slots() ); |
200
|
|
|
|
|
|
|
}; |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
around _inline_weaken_value => sub { |
203
|
|
|
|
|
|
|
shift; |
204
|
|
|
|
|
|
|
my $self = shift; |
205
|
|
|
|
|
|
|
shift; |
206
|
|
|
|
|
|
|
my $value = shift; |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
return unless $self->is_weak_ref(); |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
return ( |
211
|
|
|
|
|
|
|
$self->associated_class->_inline_weaken_class_slot_value( |
212
|
|
|
|
|
|
|
$self->slots(), $value |
213
|
|
|
|
|
|
|
), |
214
|
|
|
|
|
|
|
'if ref ' . $value . ';', |
215
|
|
|
|
|
|
|
); |
216
|
|
|
|
|
|
|
}; |
217
|
|
|
|
|
|
|
} |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
1; |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
# ABSTRACT: A trait for class attributes |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
__END__ |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
=pod |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
=encoding UTF-8 |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
=head1 NAME |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
MooseX::ClassAttribute::Trait::Attribute - A trait for class attributes |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
=head1 VERSION |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
version 0.29 |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
=head1 DESCRIPTION |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
This role modifies the behavior of class attributes in various |
240
|
|
|
|
|
|
|
ways. It really should be a subclass of C<Moose::Meta::Attribute>, but |
241
|
|
|
|
|
|
|
if it were then it couldn't be combined with other attribute |
242
|
|
|
|
|
|
|
metaclasses, like C<MooseX::AttributeHelpers>. |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
There are no new public methods implemented by this role. All it does |
245
|
|
|
|
|
|
|
is change the behavior of a number of existing methods. |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
=head1 BUGS |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
See L<MooseX::ClassAttribute> for details. |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
Bugs may be submitted through L<the RT bug tracker|http://rt.cpan.org/Public/Dist/Display.html?Name=MooseX-ClassAttribute> |
252
|
|
|
|
|
|
|
(or L<bug-moosex-classattribute@rt.cpan.org|mailto:bug-moosex-classattribute@rt.cpan.org>). |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
I am also usually active on IRC as 'drolsky' on C<irc://irc.perl.org>. |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
=head1 AUTHOR |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
Dave Rolsky <autarch@urth.org> |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENCE |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
This software is Copyright (c) 2016 by Dave Rolsky. |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
This is free software, licensed under: |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
The Artistic License 2.0 (GPL Compatible) |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
=cut |