line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# ABSTRACT: Role Declaration DSL for Perl 5 |
2
|
|
|
|
|
|
|
package Data::Object::Role::Syntax; |
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
25224
|
use 5.010; |
|
1
|
|
|
|
|
2
|
|
5
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
34
|
|
6
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
79
|
|
7
|
1
|
|
|
1
|
|
568
|
use parent 'Exporter'; |
|
1
|
|
|
|
|
299
|
|
|
1
|
|
|
|
|
5
|
|
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
588
|
use Sub::Quote; |
|
1
|
|
|
|
|
13796
|
|
|
1
|
|
|
|
|
165
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.41'; # VERSION |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our @EXPORT = qw( |
14
|
|
|
|
|
|
|
alt |
15
|
|
|
|
|
|
|
builder |
16
|
|
|
|
|
|
|
clearer |
17
|
|
|
|
|
|
|
coerce |
18
|
|
|
|
|
|
|
def |
19
|
|
|
|
|
|
|
default |
20
|
|
|
|
|
|
|
defaulter |
21
|
|
|
|
|
|
|
handles |
22
|
|
|
|
|
|
|
init_arg |
23
|
|
|
|
|
|
|
is |
24
|
|
|
|
|
|
|
isa |
25
|
|
|
|
|
|
|
lazy |
26
|
|
|
|
|
|
|
opt |
27
|
|
|
|
|
|
|
optional |
28
|
|
|
|
|
|
|
predicate |
29
|
|
|
|
|
|
|
reader |
30
|
|
|
|
|
|
|
req |
31
|
|
|
|
|
|
|
required |
32
|
|
|
|
|
|
|
ro |
33
|
|
|
|
|
|
|
rw |
34
|
|
|
|
|
|
|
trigger |
35
|
|
|
|
|
|
|
weak_ref |
36
|
|
|
|
|
|
|
writer |
37
|
|
|
|
|
|
|
); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub import { |
40
|
0
|
|
|
0
|
|
0
|
my $class = $_[0]; |
41
|
0
|
|
|
|
|
0
|
my $target = caller; |
42
|
|
|
|
|
|
|
|
43
|
0
|
0
|
|
|
|
0
|
if (my $orig = $target->can('has')) { |
44
|
|
|
|
|
|
|
|
45
|
1
|
|
|
1
|
|
11
|
no strict 'refs'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
44
|
|
46
|
1
|
|
|
1
|
|
5
|
no warnings 'redefine'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
974
|
|
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
0
|
my $has = *{"${target}::has"} = sub { |
49
|
0
|
|
|
0
|
|
0
|
my ($name, @props) = @_; |
50
|
|
|
|
|
|
|
|
51
|
0
|
0
|
|
|
|
0
|
return $orig->($name, @props) |
52
|
|
|
|
|
|
|
if @props % 2 != 0; |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
0
|
my $alt = $name =~ s/^\+//; |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
0
|
my %codes = ( |
57
|
|
|
|
|
|
|
builder => 'build', |
58
|
|
|
|
|
|
|
clearer => 'clear', |
59
|
|
|
|
|
|
|
predicate => 'has', |
60
|
|
|
|
|
|
|
reader => 'get', |
61
|
|
|
|
|
|
|
trigger => 'trigger', |
62
|
|
|
|
|
|
|
writer => 'set', |
63
|
|
|
|
|
|
|
); |
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
0
|
my %props = @props; |
66
|
0
|
|
|
|
|
0
|
for my $code (sort keys %codes) { |
67
|
0
|
0
|
0
|
|
|
0
|
if ($props{$code} and $props{$code} eq "1") { |
68
|
0
|
|
|
|
|
0
|
my $id = $codes{$code}; |
69
|
0
|
|
|
|
|
0
|
$props{$code} = "_${id}_${name}"; |
70
|
0
|
|
|
|
|
0
|
$props{$code} =~ s/_${id}__/_${id}_/; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
0
|
0
|
|
|
|
0
|
if (my $method = delete $props{defaulter}) { |
75
|
0
|
0
|
|
|
|
0
|
if ($method eq "1") { |
76
|
0
|
|
|
|
|
0
|
$method = "_default_${name}"; |
77
|
0
|
|
|
|
|
0
|
$method =~ s/_default__/_default_/; |
78
|
|
|
|
|
|
|
} |
79
|
0
|
|
|
|
|
0
|
my $routine = q{ $target->$method(@_) }; |
80
|
0
|
|
|
|
|
0
|
$props{default} = Sub::Quote::quote_sub($routine, { |
81
|
|
|
|
|
|
|
'$target' => \$target, |
82
|
|
|
|
|
|
|
'$method' => \$method, |
83
|
|
|
|
|
|
|
}); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
0
|
0
|
|
|
|
0
|
return $orig->($alt ? "+$name" : $name, %props); |
87
|
0
|
|
|
|
|
0
|
}; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
0
|
return $class->export_to_level(1, @_); |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub alt ($@) { |
95
|
10
|
|
|
10
|
1
|
3313
|
my ($name, @props) = @_; |
96
|
10
|
50
|
|
|
|
92
|
if (my $has = caller->can('has')) { |
97
|
10
|
50
|
|
|
|
25
|
my @name = ref $name ? @$name : $name; |
98
|
10
|
50
|
|
|
|
97
|
@_ = ((map "+$_", @name), @props) and goto $has; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub builder (;$) { |
103
|
2
|
|
100
|
2
|
1
|
1632
|
return builder => $_[0] // 1; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub clearer (;$) { |
107
|
2
|
|
100
|
2
|
1
|
1536
|
return clearer => $_[0] // 1; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub coerce () { |
111
|
1
|
|
|
1
|
1
|
1513
|
return coerce => 1; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub def ($$@) { |
115
|
2
|
|
|
2
|
1
|
1988
|
my ($name, $code, @props) = @_; |
116
|
2
|
50
|
|
|
|
15
|
@_ = ($name, 'default', $code, @props) and goto &alt; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub default ($) { |
120
|
2
|
|
|
2
|
1
|
1516
|
return default => $_[0]; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub defaulter (;$) { |
124
|
1
|
|
50
|
1
|
1
|
1757
|
return defaulter => $_[0] // 1; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub handles ($) { |
128
|
3
|
|
|
3
|
1
|
1630
|
return handles => $_[0]; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub init_arg ($) { |
132
|
1
|
|
|
1
|
1
|
2081
|
return init_arg => $_[0]; |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
sub is (@) { |
136
|
1
|
|
|
1
|
1
|
1520
|
return (@_); |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
sub isa ($) { |
140
|
5
|
|
|
5
|
1
|
1713
|
return isa => $_[0]; |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
sub lazy () { |
144
|
1
|
|
|
1
|
1
|
1651
|
return lazy => 1; |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
sub opt ($;$@) { |
148
|
3
|
|
|
3
|
1
|
2589
|
my ($name, $type, @props) = @_; |
149
|
3
|
|
|
|
|
8
|
my @req = (required => 0); |
150
|
3
|
100
|
|
|
|
19
|
@_ = ($name, ref($type) ? isa($type) : (), @props, @req) |
|
|
50
|
|
|
|
|
|
151
|
|
|
|
|
|
|
and goto &alt; |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
sub optional (@) { |
155
|
1
|
|
|
1
|
1
|
1856
|
return required => 0, @_; |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
sub predicate (;$) { |
159
|
2
|
|
100
|
2
|
1
|
1503
|
return predicate => $_[0] // 1; |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
sub reader (;$) { |
163
|
2
|
|
100
|
2
|
1
|
1477
|
return reader => $_[0] // 1; |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
sub req ($;$@) { |
167
|
3
|
|
|
3
|
1
|
3084
|
my ($name, $type, @props) = @_; |
168
|
3
|
|
|
|
|
7
|
my @req = (required => 1); |
169
|
3
|
100
|
|
|
|
26
|
@_ = ($name, ref($type) ? isa($type) : (), @props, @req) |
|
|
50
|
|
|
|
|
|
170
|
|
|
|
|
|
|
and goto &alt; |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
sub required (@) { |
174
|
1
|
|
|
1
|
1
|
2399
|
return required => 1, @_; |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
sub ro () { |
178
|
1
|
|
|
1
|
1
|
2294
|
return is => 'ro'; |
179
|
|
|
|
|
|
|
} |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
sub rw () { |
182
|
1
|
|
|
1
|
1
|
2286
|
return is => 'rw'; |
183
|
|
|
|
|
|
|
} |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
sub trigger (;$) { |
186
|
2
|
|
100
|
2
|
1
|
2492
|
return trigger => $_[0] // 1; |
187
|
|
|
|
|
|
|
} |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
sub weak_ref () { |
190
|
1
|
|
|
1
|
1
|
2420
|
return weak_ref => 1; |
191
|
|
|
|
|
|
|
} |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
sub writer (;$) { |
194
|
2
|
|
100
|
2
|
1
|
2195
|
return writer => $_[0] // 1; |
195
|
|
|
|
|
|
|
} |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
1; |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
__END__ |