line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
109
|
|
|
109
|
|
2294
|
use 5.010001; |
|
109
|
|
|
|
|
458
|
|
2
|
109
|
|
|
109
|
|
851
|
use strict; |
|
109
|
|
|
|
|
286
|
|
|
109
|
|
|
|
|
2548
|
|
3
|
109
|
|
|
109
|
|
779
|
use warnings; |
|
109
|
|
|
|
|
360
|
|
|
109
|
|
|
|
|
5535
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Mite::Trait::HasAttributes; |
6
|
109
|
|
|
109
|
|
855
|
use Mite::Miteception -role, -all; |
|
109
|
|
|
|
|
308
|
|
|
109
|
|
|
|
|
1020
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:TOBYINK'; |
9
|
|
|
|
|
|
|
our $VERSION = '0.012000'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
requires qw( _function_for_croak ); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
has attributes => |
14
|
|
|
|
|
|
|
is => ro, |
15
|
|
|
|
|
|
|
isa => HashRef[MiteAttribute], |
16
|
|
|
|
|
|
|
default => sub { {} }; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub all_attributes { |
19
|
276
|
|
|
276
|
0
|
2436
|
shift->attributes; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
signature_for add_attributes => ( |
23
|
|
|
|
|
|
|
pos => [ slurpy ArrayRef[MiteAttribute] ], |
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub add_attributes { |
27
|
124
|
|
|
124
|
0
|
425
|
my ( $self, $attributes ) = @_; |
28
|
|
|
|
|
|
|
|
29
|
124
|
|
|
|
|
381
|
for my $attribute (@$attributes) { |
30
|
|
|
|
|
|
|
croak '%s already has an attribute called %s', $self->name, $attribute->_q_name |
31
|
133
|
50
|
|
|
|
955
|
if $self->attributes->{ $attribute->name }; |
32
|
133
|
|
|
|
|
620
|
$self->attributes->{ $attribute->name } = $attribute; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
124
|
|
|
|
|
443
|
return; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub add_attribute { |
39
|
116
|
|
|
116
|
0
|
3393
|
shift->add_attributes( @_ ); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub extend_attribute { |
43
|
1
|
|
|
1
|
0
|
7
|
my ($self, %attr_args) = ( shift, @_ ); |
44
|
|
|
|
|
|
|
|
45
|
1
|
|
|
|
|
4
|
my $name = delete $attr_args{name}; |
46
|
|
|
|
|
|
|
|
47
|
1
|
|
|
|
|
4
|
my $attr = $self->attributes->{$name}; |
48
|
1
|
50
|
|
|
|
4
|
croak <<'ERROR', $name, $self->name unless $attr; |
49
|
|
|
|
|
|
|
Could not find an attribute by the name of '%s' to extend in %s |
50
|
|
|
|
|
|
|
ERROR |
51
|
|
|
|
|
|
|
|
52
|
1
|
50
|
|
|
|
5
|
if ( ref $attr_args{default} ) { |
53
|
0
|
|
|
|
|
0
|
$attr_args{_class_for_default} = $self; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
1
|
|
|
|
|
5
|
$self->attributes->{$name} = $attr->clone(%attr_args); |
57
|
|
|
|
|
|
|
|
58
|
1
|
|
|
|
|
8
|
return; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
before inject_mite_functions => sub { |
62
|
|
|
|
|
|
|
my ( $self, $file, $arg ) = ( shift, @_ ); |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
my $requested = sub { $arg->{$_[0]} ? 1 : $arg->{'!'.$_[0]} ? 0 : $arg->{'-all'} ? 1 : $_[1]; }; |
65
|
|
|
|
|
|
|
my $defaults = ! $arg->{'!-defaults'}; |
66
|
|
|
|
|
|
|
my $shim = $self->shim_name; |
67
|
|
|
|
|
|
|
my $package = $self->name; |
68
|
|
|
|
|
|
|
my $kind = $self->kind; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
my $ctxt = sub { |
71
|
|
|
|
|
|
|
my $level = shift; |
72
|
|
|
|
|
|
|
my @info = caller( $level ); |
73
|
|
|
|
|
|
|
return { |
74
|
|
|
|
|
|
|
'toolkit' => 'Mite', |
75
|
|
|
|
|
|
|
'package' => $info[0], |
76
|
|
|
|
|
|
|
'file' => $info[1], |
77
|
|
|
|
|
|
|
'line' => $info[2], |
78
|
|
|
|
|
|
|
@_, |
79
|
|
|
|
|
|
|
}; |
80
|
|
|
|
|
|
|
}; |
81
|
|
|
|
|
|
|
|
82
|
109
|
|
|
109
|
|
1018
|
no strict 'refs'; |
|
109
|
|
|
|
|
536
|
|
|
109
|
|
|
|
|
89012
|
|
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
my $has = sub { |
85
|
2
|
|
|
2
|
|
5
|
my $names = shift; |
86
|
2
|
50
|
|
|
|
8
|
if ( @_ % 2 ) { |
87
|
0
|
|
|
|
|
0
|
my $default = shift; |
88
|
0
|
0
|
|
|
|
0
|
unshift @_, ( 'CODE' eq ref( $default ) ) |
89
|
|
|
|
|
|
|
? ( is => lazy, builder => $default ) |
90
|
|
|
|
|
|
|
: ( is => ro, default => $default ); |
91
|
|
|
|
|
|
|
} |
92
|
2
|
|
|
|
|
8
|
my %spec = @_; |
93
|
2
|
|
33
|
|
|
7
|
$spec{definition_context} ||= $ctxt->( 1, file => "$file", type => $kind, context => 'has declaration' ); |
94
|
|
|
|
|
|
|
|
95
|
2
|
50
|
|
|
|
9
|
for my $name ( ref($names) ? @$names : $names ) { |
96
|
2
|
50
|
|
|
|
15
|
if( my $is_extension = $name =~ s{^\+}{} ) { |
97
|
0
|
|
|
|
|
0
|
$self->extend_attribute( |
98
|
|
|
|
|
|
|
class => $self, |
99
|
|
|
|
|
|
|
name => $name, |
100
|
|
|
|
|
|
|
%spec |
101
|
|
|
|
|
|
|
); |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
else { |
104
|
2
|
|
|
|
|
710
|
require Mite::Attribute; |
105
|
2
|
|
|
|
|
19
|
my $attribute = Mite::Attribute->new( |
106
|
|
|
|
|
|
|
class => $self, |
107
|
|
|
|
|
|
|
name => $name, |
108
|
|
|
|
|
|
|
%spec |
109
|
|
|
|
|
|
|
); |
110
|
2
|
|
|
|
|
11
|
$self->add_attribute($attribute); |
111
|
|
|
|
|
|
|
} |
112
|
2
|
|
|
|
|
5
|
my $code; |
113
|
|
|
|
|
|
|
'CODE' eq ref( $code = $spec{builder} ) |
114
|
2
|
50
|
|
|
|
7
|
and *{"$package\::_build_$name"} = $code; |
|
0
|
|
|
|
|
0
|
|
115
|
|
|
|
|
|
|
'CODE' eq ref( $code = $spec{trigger} ) |
116
|
2
|
50
|
|
|
|
7
|
and *{"$package\::_trigger_$name"} = $code; |
|
0
|
|
|
|
|
0
|
|
117
|
|
|
|
|
|
|
'CODE' eq ref( $code = $spec{clone} ) |
118
|
2
|
50
|
|
|
|
13
|
and *{"$package\::_clone_$name"} = $code; |
|
0
|
|
|
|
|
0
|
|
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
2
|
|
|
|
|
12
|
return; |
122
|
|
|
|
|
|
|
}; |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
if ( $requested->( 'has', $defaults ) ) { |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
*{ $package .'::has' } = $has; |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
$self->imported_keywords->{has} = 'sub { $SHIM->HANDLE_has( $CALLER, has => @_ ) }'; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
if ( $requested->( 'param', false ) ) { |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
*{"$package\::param"} = sub { |
134
|
1
|
|
|
1
|
|
4
|
my ( $names, %spec ) = @_; |
135
|
1
|
50
|
|
|
|
10
|
$spec{is} = ro unless exists $spec{is}; |
136
|
1
|
50
|
|
|
|
7
|
$spec{required} = true unless exists $spec{required}; |
137
|
1
|
|
33
|
|
|
17
|
$spec{definition_context} ||= $ctxt->( 1, file => "$file", type => $kind, context => 'param declaration' ); |
138
|
1
|
|
|
|
|
4
|
$has->( $names, %spec ); |
139
|
|
|
|
|
|
|
}; |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
$self->imported_keywords->{param} = 'sub { $SHIM->HANDLE_has( $CALLER, param => @_ ) }'; |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
if ( $requested->( 'field', false ) ) { |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
*{"$package\::field"} = sub { |
147
|
1
|
|
|
1
|
|
7
|
my ( $names, %spec ) = @_; |
148
|
1
|
50
|
33
|
|
|
12
|
$spec{is} ||= ( $spec{builder} || exists $spec{default} ) ? lazy : rwp; |
|
|
|
33
|
|
|
|
|
149
|
1
|
50
|
|
|
|
7
|
$spec{init_arg} = undef unless exists $spec{init_arg}; |
150
|
1
|
50
|
33
|
|
|
4
|
if ( defined $spec{init_arg} and $spec{init_arg} !~ /^_/ ) { |
151
|
0
|
|
|
|
|
0
|
croak "A defined 'field.init_arg' must begin with an underscore: %s ", $spec{init_arg}; |
152
|
|
|
|
|
|
|
} |
153
|
1
|
|
33
|
|
|
9
|
$spec{definition_context} ||= $ctxt->( 1, file => "$file", type => $kind, context => 'field declaration' ); |
154
|
1
|
|
|
|
|
8
|
$has->( $names, %spec ); |
155
|
|
|
|
|
|
|
}; |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
$self->imported_keywords->{field} = 'sub { $SHIM->HANDLE_has( $CALLER, field => @_ ) }'; |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
}; |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
sub _compile_init_attributes { |
162
|
104
|
|
|
104
|
|
489
|
my ( $self, $classvar, $selfvar, $argvar, $metavar ) = @_; |
163
|
|
|
|
|
|
|
|
164
|
104
|
|
|
|
|
250
|
my @code; |
165
|
104
|
|
|
|
|
272
|
my $depth = 1; |
166
|
104
|
|
|
|
|
497
|
my %depth = map { $_ => $depth++; } $self->linear_isa; |
|
126
|
|
|
|
|
738
|
|
167
|
104
|
|
|
|
|
314
|
my @attributes = do { |
168
|
109
|
|
|
109
|
|
1004
|
no warnings; |
|
109
|
|
|
|
|
486
|
|
|
109
|
|
|
|
|
91568
|
|
169
|
|
|
|
|
|
|
sort { |
170
|
69
|
50
|
|
|
|
174
|
eval { $depth{$b->class->name} <=> $depth{$a->class->name} } |
|
69
|
|
|
|
|
261
|
|
171
|
|
|
|
|
|
|
or $a->_order <=> $b->_order; |
172
|
|
|
|
|
|
|
} |
173
|
104
|
|
|
|
|
298
|
values %{ $self->all_attributes }; |
|
104
|
|
|
|
|
3040
|
|
174
|
|
|
|
|
|
|
}; |
175
|
104
|
|
|
|
|
411
|
for my $attr ( @attributes ) { |
176
|
129
|
|
|
|
|
621
|
my $guard = $attr->locally_set_compiling_class( $self ); |
177
|
129
|
|
|
|
|
1012
|
my @lines = grep !!$_, $attr->compile_init( $selfvar, $argvar ); |
178
|
129
|
100
|
|
|
|
546
|
if ( @lines ) { |
179
|
126
|
100
|
|
|
|
480
|
push @code, sprintf "# Attribute %s%s", |
180
|
|
|
|
|
|
|
$attr->name, $attr->type ? sprintf( ' (type: %s)', $attr->type->display_name ) : ''; |
181
|
126
|
|
|
|
|
1022
|
push @code, sprintf '# %s', |
182
|
|
|
|
|
|
|
$attr->definition_context_to_pretty_string; |
183
|
126
|
|
|
|
|
406
|
push @code, @lines; |
184
|
126
|
|
|
|
|
840
|
push @code, ''; |
185
|
|
|
|
|
|
|
} |
186
|
|
|
|
|
|
|
} |
187
|
|
|
|
|
|
|
|
188
|
104
|
100
|
|
|
|
684
|
return join "\n", map { /\S/ ? " $_" : '' } @code; |
|
521
|
|
|
|
|
2941
|
|
189
|
|
|
|
|
|
|
} |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
sub _needs_accessors { |
192
|
0
|
|
|
0
|
|
0
|
return false; |
193
|
|
|
|
|
|
|
} |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
around _compile_pragmas => sub { |
196
|
|
|
|
|
|
|
my ( $next, $self ) = ( shift, shift ); |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
my $code = $self->$next( @_ ); |
199
|
|
|
|
|
|
|
return $code unless |
200
|
|
|
|
|
|
|
grep { defined($_) and $_ eq true } |
201
|
|
|
|
|
|
|
map { $_->cloner_method } |
202
|
|
|
|
|
|
|
values %{ $self->all_attributes }; |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
return "use Storable ();\n" . $code; |
205
|
|
|
|
|
|
|
}; |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
around compilation_stages => sub { |
208
|
|
|
|
|
|
|
my ( $next, $self ) = ( shift, shift ); |
209
|
|
|
|
|
|
|
my @stages = $self->$next( @_ ); |
210
|
|
|
|
|
|
|
push @stages, qw( |
211
|
|
|
|
|
|
|
_compile_attribute_accessors |
212
|
|
|
|
|
|
|
) if $self->_needs_accessors; |
213
|
|
|
|
|
|
|
return @stages; |
214
|
|
|
|
|
|
|
}; |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
sub _compile_attribute_accessors { |
217
|
114
|
|
|
114
|
|
335
|
my $self = shift; |
218
|
|
|
|
|
|
|
|
219
|
114
|
|
|
|
|
591
|
my $attributes = $self->attributes; |
220
|
114
|
100
|
|
|
|
747
|
keys %$attributes or return ''; |
221
|
|
|
|
|
|
|
|
222
|
81
|
|
|
|
|
289
|
my $code = 'my $__XS = !$ENV{PERL_ONLY} && eval { require Class::XSAccessor; Class::XSAccessor->VERSION("1.19") };' . "\n\n"; |
223
|
81
|
|
|
|
|
416
|
for my $name ( sort keys %$attributes ) { |
224
|
114
|
|
|
|
|
694
|
my $guard = $attributes->{$name}->locally_set_compiling_class( $self ); |
225
|
114
|
|
|
|
|
1039
|
$code .= $attributes->{$name}->compile( xs_condition => '$__XS' ); |
226
|
|
|
|
|
|
|
} |
227
|
|
|
|
|
|
|
|
228
|
81
|
|
|
|
|
711
|
return $code; |
229
|
|
|
|
|
|
|
} |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
around _compile_mop_attributes => sub { |
232
|
|
|
|
|
|
|
my ( $next, $self ) = ( shift, shift ); |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
my $code = $self->$next( @_ ); |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
my @attrs = |
237
|
|
|
|
|
|
|
sort { $a->_order <=> $b->_order } |
238
|
|
|
|
|
|
|
values %{ $self->attributes }; |
239
|
|
|
|
|
|
|
if ( @attrs ) { |
240
|
|
|
|
|
|
|
$code .= " my \%ATTR;\n\n"; |
241
|
|
|
|
|
|
|
for my $attr ( @attrs ) { |
242
|
|
|
|
|
|
|
my $guard = $attr->locally_set_compiling_class( $self ); |
243
|
|
|
|
|
|
|
my $attr_code = $attr->_compile_mop; |
244
|
|
|
|
|
|
|
$attr_code =~ s/^/ /gm; |
245
|
|
|
|
|
|
|
$code .= $attr_code . "\n"; |
246
|
|
|
|
|
|
|
} |
247
|
|
|
|
|
|
|
} |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
return $code; |
250
|
|
|
|
|
|
|
}; |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
1; |