line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Moxie::Traits::Provider::Accessor; |
2
|
|
|
|
|
|
|
# ABSTRACT: built in traits |
3
|
|
|
|
|
|
|
|
4
|
49
|
|
|
51
|
|
472
|
use v5.22; |
|
49
|
|
|
|
|
143
|
|
5
|
49
|
|
|
49
|
|
226
|
use warnings; |
|
49
|
|
|
|
|
78
|
|
|
49
|
|
|
|
|
1743
|
|
6
|
49
|
|
|
|
|
214
|
use experimental qw[ |
7
|
|
|
|
|
|
|
signatures |
8
|
|
|
|
|
|
|
postderef |
9
|
49
|
|
|
49
|
|
270
|
]; |
|
49
|
|
|
|
|
86
|
|
10
|
|
|
|
|
|
|
|
11
|
49
|
|
|
49
|
|
6059
|
use Method::Traits ':for_providers'; |
|
49
|
|
|
|
|
115
|
|
|
49
|
|
|
|
|
293
|
|
12
|
|
|
|
|
|
|
|
13
|
49
|
|
|
49
|
|
16374
|
use Carp (); |
|
49
|
|
|
|
|
111
|
|
|
49
|
|
|
|
|
900
|
|
14
|
49
|
|
|
49
|
|
205
|
use MOP::Util (); |
|
49
|
|
|
|
|
96
|
|
|
49
|
|
|
|
|
14713
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = '0.07'; |
17
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:STEVAN'; |
18
|
|
|
|
|
|
|
|
19
|
37
|
|
|
37
|
0
|
50
|
sub ro ( $meta, $method, @args ) : OverwritesMethod { |
|
37
|
|
|
|
|
17933
|
|
|
37
|
|
|
|
|
63
|
|
|
37
|
|
|
|
|
65
|
|
|
37
|
|
|
|
|
62
|
|
20
|
|
|
|
|
|
|
|
21
|
37
|
|
|
|
|
133
|
my $method_name = $method->name; |
22
|
|
|
|
|
|
|
|
23
|
37
|
|
|
|
|
529
|
my $slot_name; |
24
|
37
|
100
|
|
|
|
102
|
if ( $args[0] ) { |
25
|
32
|
|
|
|
|
68
|
$slot_name = shift @args; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
else { |
28
|
5
|
100
|
|
|
|
20
|
if ( $method_name =~ /^get_(.*)$/ ) { |
29
|
1
|
|
|
|
|
4
|
$slot_name = $1; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
else { |
32
|
4
|
|
|
|
|
6
|
$slot_name = $method_name; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
37
|
50
|
33
|
|
|
150
|
Carp::confess('Unable to build `ro` accessor for slot `' . $slot_name.'` in `'.$meta->name.'` because the slot cannot be found.') |
37
|
|
|
|
|
|
|
unless $meta->has_slot( $slot_name ) |
38
|
|
|
|
|
|
|
|| $meta->has_slot_alias( $slot_name ); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
$meta->add_method( $method_name => sub { |
41
|
203
|
50
|
|
203
|
|
24483
|
Carp::confess("Cannot assign to `$slot_name`, it is a readonly") if scalar @_ != 1; |
|
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
|
52
|
|
|
|
42
|
203
|
|
|
|
|
752
|
$_[0]->{ $slot_name }; |
43
|
37
|
|
|
|
|
4886
|
}); |
44
|
49
|
|
|
49
|
|
311
|
} |
|
49
|
|
|
|
|
88
|
|
|
49
|
|
|
|
|
325
|
|
45
|
|
|
|
|
|
|
|
46
|
1
|
|
|
1
|
0
|
2
|
sub rw ( $meta, $method, @args ) : OverwritesMethod { |
|
1
|
|
|
|
|
592
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
2
|
|
47
|
|
|
|
|
|
|
|
48
|
1
|
|
|
|
|
2
|
my $method_name = $method->name; |
49
|
|
|
|
|
|
|
|
50
|
1
|
|
|
|
|
13
|
my $slot_name; |
51
|
1
|
50
|
|
|
|
3
|
if ( $args[0] ) { |
52
|
0
|
|
|
|
|
0
|
$slot_name = shift @args; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
else { |
55
|
1
|
|
|
|
|
3
|
$slot_name = $method_name; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
1
|
50
|
|
|
|
7
|
Carp::confess('Unable to build `rw` accessor for slot `' . $slot_name.'` in `'.$meta->name.'` because class is immutable.') |
59
|
|
|
|
|
|
|
if ($meta->name)->isa('Moxie::Object::Immutable'); |
60
|
|
|
|
|
|
|
|
61
|
1
|
50
|
33
|
|
|
23
|
Carp::confess('Unable to build `rw` accessor for slot `' . $slot_name.'` in `'.$meta->name.'` because the slot cannot be found.') |
62
|
|
|
|
|
|
|
unless $meta->has_slot( $slot_name ) |
63
|
|
|
|
|
|
|
|| $meta->has_slot_alias( $slot_name ); |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
$meta->add_method( $method_name => sub { |
66
|
0
|
0
|
|
0
|
|
0
|
$_[0]->{ $slot_name } = $_[1] if scalar( @_ ) > 1; |
67
|
0
|
|
|
|
|
0
|
$_[0]->{ $slot_name }; |
68
|
1
|
|
|
|
|
124
|
}); |
69
|
49
|
|
|
49
|
|
36465
|
} |
|
49
|
|
|
|
|
98
|
|
|
49
|
|
|
|
|
192
|
|
70
|
|
|
|
|
|
|
|
71
|
14
|
|
|
14
|
0
|
21
|
sub wo ( $meta, $method, @args ) : OverwritesMethod { |
|
14
|
|
|
|
|
8127
|
|
|
14
|
|
|
|
|
26
|
|
|
14
|
|
|
|
|
22
|
|
|
14
|
|
|
|
|
37
|
|
72
|
|
|
|
|
|
|
|
73
|
14
|
|
|
|
|
41
|
my $method_name = $method->name; |
74
|
|
|
|
|
|
|
|
75
|
14
|
|
|
|
|
190
|
my $slot_name; |
76
|
14
|
100
|
|
|
|
38
|
if ( $args[0] ) { |
77
|
13
|
|
|
|
|
28
|
$slot_name = shift @args; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
else { |
80
|
1
|
50
|
|
|
|
6
|
if ( $method_name =~ /^set_(.*)$/ ) { |
81
|
1
|
|
|
|
|
3
|
$slot_name = $1; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
else { |
84
|
0
|
|
|
|
|
0
|
$slot_name = $method_name; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
14
|
50
|
|
|
|
36
|
Carp::confess('Unable to build `wo` accessor for slot `' . $slot_name.'` in `'.$meta->name.'` because class is immutable.') |
89
|
|
|
|
|
|
|
if ($meta->name)->isa('Moxie::Object::Immutable'); |
90
|
|
|
|
|
|
|
|
91
|
14
|
50
|
33
|
|
|
266
|
Carp::confess('Unable to build `wo` accessor for slot `' . $slot_name.'` in `'.$meta->name.'` because the slot cannot be found.') |
92
|
|
|
|
|
|
|
unless $meta->has_slot( $slot_name ) |
93
|
|
|
|
|
|
|
|| $meta->has_slot_alias( $slot_name ); |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
$meta->add_method( $method_name => sub { |
96
|
51
|
50
|
|
51
|
|
248
|
Carp::confess("You must supply a value to write to `$slot_name`") if scalar(@_) < 1; |
|
|
|
|
237
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
|
90
|
|
|
|
97
|
51
|
|
|
|
|
115
|
$_[0]->{ $slot_name } = $_[1]; |
98
|
14
|
|
|
|
|
1778
|
}); |
99
|
49
|
|
|
49
|
|
32543
|
} |
|
49
|
|
|
|
|
95
|
|
|
49
|
|
|
|
|
182
|
|
100
|
|
|
|
|
|
|
|
101
|
13
|
|
|
39
|
0
|
22
|
sub predicate ( $meta, $method, @args ) : OverwritesMethod { |
|
13
|
|
|
|
|
7915
|
|
|
13
|
|
|
|
|
25
|
|
|
13
|
|
|
|
|
19
|
|
|
13
|
|
|
|
|
24
|
|
102
|
|
|
|
|
|
|
|
103
|
13
|
|
|
|
|
31
|
my $method_name = $method->name; |
104
|
|
|
|
|
|
|
|
105
|
13
|
|
|
|
|
180
|
my $slot_name; |
106
|
13
|
100
|
|
|
|
42
|
if ( $args[0] ) { |
107
|
11
|
|
|
|
|
24
|
$slot_name = shift @args; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
else { |
110
|
2
|
50
|
|
|
|
7
|
if ( $method_name =~ /^has_(.*)$/ ) { |
111
|
2
|
|
|
|
|
6
|
$slot_name = $1; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
else { |
114
|
0
|
|
|
|
|
0
|
$slot_name = $method_name; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
13
|
50
|
33
|
|
|
40
|
Carp::confess('Unable to build predicate for slot `' . $slot_name.'` in `'.$meta->name.'` because the slot cannot be found.') |
119
|
|
|
|
|
|
|
unless $meta->has_slot( $slot_name ) |
120
|
|
|
|
|
|
|
|| $meta->has_slot_alias( $slot_name ); |
121
|
|
|
|
|
|
|
|
122
|
13
|
|
|
90
|
|
1805
|
$meta->add_method( $method_name => sub { defined $_[0]->{ $slot_name } } ); |
|
64
|
|
|
|
|
22274
|
|
123
|
49
|
|
|
49
|
|
28932
|
} |
|
49
|
|
|
|
|
139
|
|
|
49
|
|
|
|
|
184
|
|
124
|
|
|
|
|
|
|
|
125
|
10
|
|
|
96
|
0
|
13
|
sub clearer ( $meta, $method, @args ) : OverwritesMethod { |
|
10
|
|
|
|
|
5708
|
|
|
10
|
|
|
|
|
34
|
|
|
10
|
|
|
|
|
14
|
|
|
10
|
|
|
|
|
23
|
|
126
|
|
|
|
|
|
|
|
127
|
10
|
|
|
|
|
41
|
my $method_name = $method->name; |
128
|
|
|
|
|
|
|
|
129
|
10
|
|
|
|
|
147
|
my $slot_name; |
130
|
10
|
50
|
|
|
|
34
|
if ( $args[0] ) { |
131
|
10
|
|
|
|
|
19
|
$slot_name = shift @args; |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
else { |
134
|
0
|
0
|
|
|
|
0
|
if ( $method_name =~ /^clear_(.*)$/ ) { |
135
|
0
|
|
|
|
|
0
|
$slot_name = $1; |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
else { |
138
|
0
|
|
|
|
|
0
|
$slot_name = $method_name; |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
10
|
50
|
|
|
|
26
|
Carp::confess('Unable to build `clearer` accessor for slot `' . $slot_name.'` in `'.$meta->name.'` because class is immutable.') |
143
|
|
|
|
|
|
|
if ($meta->name)->isa('Moxie::Object::Immutable'); |
144
|
|
|
|
|
|
|
|
145
|
10
|
50
|
33
|
|
|
174
|
Carp::confess('Unable to build `clearer` accessor for slot `' . $slot_name.'` in `'.$meta->name.'` because the slot cannot be found.') |
146
|
|
|
|
|
|
|
unless $meta->has_slot( $slot_name ) |
147
|
|
|
|
|
|
|
|| $meta->has_slot_alias( $slot_name ); |
148
|
|
|
|
|
|
|
|
149
|
10
|
|
|
36
|
|
1293
|
$meta->add_method( $method_name => sub { undef $_[0]->{ $slot_name } } ); |
|
18
|
|
|
|
|
68
|
|
150
|
49
|
|
|
49
|
|
30411
|
} |
|
49
|
|
|
|
|
104
|
|
|
49
|
|
|
|
|
199
|
|
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
1; |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
__END__ |