line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
108
|
|
|
108
|
|
2048
|
use 5.010001; |
|
108
|
|
|
|
|
331
|
|
2
|
108
|
|
|
108
|
|
617
|
use strict; |
|
108
|
|
|
|
|
224
|
|
|
108
|
|
|
|
|
2311
|
|
3
|
108
|
|
|
108
|
|
501
|
use warnings; |
|
108
|
|
|
|
|
218
|
|
|
108
|
|
|
|
|
4802
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
use Mite::Miteception -role, -all; |
6
|
108
|
|
|
108
|
|
672
|
|
|
108
|
|
|
|
|
238
|
|
|
108
|
|
|
|
|
823
|
|
7
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:TOBYINK'; |
8
|
|
|
|
|
|
|
our $VERSION = '0.010008'; |
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
|
285
|
|
|
285
|
0
|
1927
|
|
20
|
|
|
|
|
|
|
signature_for add_attributes => ( |
21
|
|
|
|
|
|
|
pos => [ slurpy ArrayRef[MiteAttribute] ], |
22
|
|
|
|
|
|
|
); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
my ( $self, $attributes ) = @_; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
for my $attribute (@$attributes) { |
27
|
125
|
|
|
125
|
0
|
387
|
croak '%s already has an attribute called %s', $self->name, $attribute->_q_name |
28
|
|
|
|
|
|
|
if $self->attributes->{ $attribute->name }; |
29
|
125
|
|
|
|
|
296
|
$self->attributes->{ $attribute->name } = $attribute; |
30
|
|
|
|
|
|
|
} |
31
|
134
|
50
|
|
|
|
761
|
|
32
|
134
|
|
|
|
|
499
|
return; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
125
|
|
|
|
|
370
|
shift->add_attributes( @_ ); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
my ($self, %attr_args) = ( shift, @_ ); |
39
|
116
|
|
|
116
|
0
|
2900
|
|
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
|
|
|
|
|
3
|
ERROR |
46
|
|
|
|
|
|
|
|
47
|
1
|
|
|
|
|
3
|
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
|
|
|
|
3
|
|
53
|
0
|
|
|
|
|
0
|
return; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
1
|
|
|
|
|
4
|
before inject_mite_functions => sub { |
57
|
|
|
|
|
|
|
my ( $self, $file, $arg ) = ( shift, @_ ); |
58
|
1
|
|
|
|
|
6
|
|
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
|
108
|
|
|
108
|
|
948
|
my $default = shift; |
|
108
|
|
|
|
|
286
|
|
|
108
|
|
|
|
|
70563
|
|
83
|
|
|
|
|
|
|
unshift @_, ( 'CODE' eq ref( $default ) ) |
84
|
|
|
|
|
|
|
? ( is => lazy, builder => $default ) |
85
|
3
|
|
|
3
|
|
8
|
: ( is => ro, default => $default ); |
86
|
3
|
100
|
|
|
|
16
|
} |
87
|
1
|
|
|
|
|
4
|
my %spec = @_; |
88
|
1
|
50
|
|
|
|
10
|
$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
|
3
|
|
|
|
|
11
|
$self->extend_attribute( |
93
|
3
|
|
66
|
|
|
12
|
class => $self, |
94
|
|
|
|
|
|
|
name => $name, |
95
|
3
|
100
|
|
|
|
20
|
%spec |
96
|
3
|
100
|
|
|
|
17
|
); |
97
|
1
|
|
|
|
|
4
|
} |
98
|
|
|
|
|
|
|
else { |
99
|
|
|
|
|
|
|
require Mite::Attribute; |
100
|
|
|
|
|
|
|
my $attribute = Mite::Attribute->new( |
101
|
|
|
|
|
|
|
class => $self, |
102
|
|
|
|
|
|
|
name => $name, |
103
|
|
|
|
|
|
|
%spec |
104
|
2
|
|
|
|
|
700
|
); |
105
|
3
|
|
|
|
|
29
|
$self->add_attribute($attribute); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
my $code; |
108
|
|
|
|
|
|
|
'CODE' eq ref( $code = $spec{builder} ) |
109
|
|
|
|
|
|
|
and *{"$package\::_build_$name"} = $code; |
110
|
3
|
|
|
|
|
15
|
'CODE' eq ref( $code = $spec{trigger} ) |
111
|
|
|
|
|
|
|
and *{"$package\::_trigger_$name"} = $code; |
112
|
2
|
|
|
|
|
3
|
'CODE' eq ref( $code = $spec{clone} ) |
113
|
|
|
|
|
|
|
and *{"$package\::_clone_$name"} = $code; |
114
|
2
|
50
|
|
|
|
8
|
} |
|
0
|
|
|
|
|
0
|
|
115
|
|
|
|
|
|
|
|
116
|
2
|
50
|
|
|
|
6
|
return; |
|
0
|
|
|
|
|
0
|
|
117
|
|
|
|
|
|
|
}; |
118
|
2
|
50
|
|
|
|
8
|
|
|
0
|
|
|
|
|
0
|
|
119
|
|
|
|
|
|
|
if ( $requested->( 'has', $defaults ) ) { |
120
|
|
|
|
|
|
|
|
121
|
2
|
|
|
|
|
17
|
*{ $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
|
|
|
}; |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
$self->imported_keywords->{param} = 'sub { $SHIM->HANDLE_has( $CALLER, param => @_ ) }'; |
137
|
|
|
33
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
} |
148
|
|
|
33
|
|
|
|
$spec{definition_context} ||= $ctxt->( 1, file => "$file", type => $kind, context => 'field declaration' ); |
|
|
|
33
|
|
|
|
|
149
|
|
|
|
|
|
|
$has->( $names, %spec ); |
150
|
|
|
33
|
|
|
|
}; |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
$self->imported_keywords->{field} = 'sub { $SHIM->HANDLE_has( $CALLER, field => @_ ) }'; |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
}; |
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
|
108
|
|
|
108
|
|
369
|
no warnings; |
163
|
|
|
|
|
|
|
sort { |
164
|
108
|
|
|
|
|
201
|
eval { $depth{$b->class->name} <=> $depth{$a->class->name} } |
165
|
108
|
|
|
|
|
245
|
or $a->_order <=> $b->_order; |
166
|
108
|
|
|
|
|
434
|
} |
|
132
|
|
|
|
|
639
|
|
167
|
108
|
|
|
|
|
291
|
values %{ $self->all_attributes }; |
168
|
108
|
|
|
108
|
|
796
|
}; |
|
108
|
|
|
|
|
259
|
|
|
108
|
|
|
|
|
75857
|
|
169
|
|
|
|
|
|
|
for my $attr ( @attributes ) { |
170
|
69
|
50
|
|
|
|
143
|
my $guard = $attr->locally_set_compiling_class( $self ); |
|
69
|
|
|
|
|
207
|
|
171
|
|
|
|
|
|
|
my @lines = grep !!$_, $attr->compile_init( $selfvar, $argvar ); |
172
|
|
|
|
|
|
|
if ( @lines ) { |
173
|
108
|
|
|
|
|
203
|
push @code, sprintf "# Attribute %s%s", |
|
108
|
|
|
|
|
2544
|
|
174
|
|
|
|
|
|
|
$attr->name, $attr->type ? sprintf( ' (type: %s)', $attr->type->display_name ) : ''; |
175
|
108
|
|
|
|
|
367
|
push @code, sprintf '# %s', |
176
|
130
|
|
|
|
|
696
|
$attr->definition_context_to_pretty_string; |
177
|
130
|
|
|
|
|
883
|
push @code, @lines; |
178
|
130
|
100
|
|
|
|
471
|
push @code, ''; |
179
|
127
|
100
|
|
|
|
442
|
} |
180
|
|
|
|
|
|
|
} |
181
|
127
|
|
|
|
|
843
|
|
182
|
|
|
|
|
|
|
return join "\n", map { /\S/ ? " $_" : '' } @code; |
183
|
127
|
|
|
|
|
331
|
} |
184
|
127
|
|
|
|
|
765
|
|
185
|
|
|
|
|
|
|
return false; |
186
|
|
|
|
|
|
|
} |
187
|
|
|
|
|
|
|
|
188
|
108
|
100
|
|
|
|
422
|
around _compile_pragmas => sub { |
|
524
|
|
|
|
|
2515
|
|
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
|
122
|
|
|
122
|
|
266
|
$code .= $attributes->{$name}->compile( xs_condition => '$__XS' ); |
218
|
|
|
|
|
|
|
} |
219
|
122
|
|
|
|
|
450
|
|
220
|
122
|
100
|
|
|
|
592
|
return $code; |
221
|
|
|
|
|
|
|
} |
222
|
82
|
|
|
|
|
233
|
|
223
|
82
|
|
|
|
|
361
|
around _compile_mop_attributes => sub { |
224
|
115
|
|
|
|
|
746
|
my ( $next, $self ) = ( shift, shift ); |
225
|
115
|
|
|
|
|
766
|
|
226
|
|
|
|
|
|
|
my $code = $self->$next( @_ ); |
227
|
|
|
|
|
|
|
|
228
|
82
|
|
|
|
|
560
|
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; |