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