| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package decorators::providers::accessors; |
|
2
|
|
|
|
|
|
|
# ABSTRACT: A set of decorators to generate accessor methods |
|
3
|
|
|
|
|
|
|
|
|
4
|
4
|
|
|
4
|
|
2016
|
use strict; |
|
|
4
|
|
|
|
|
8
|
|
|
|
4
|
|
|
|
|
94
|
|
|
5
|
4
|
|
|
4
|
|
17
|
use warnings; |
|
|
4
|
|
|
|
|
6
|
|
|
|
4
|
|
|
|
|
97
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
4
|
|
|
4
|
|
20
|
use decorators ':for_providers'; |
|
|
4
|
|
|
|
|
6
|
|
|
|
4
|
|
|
|
|
23
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
4
|
|
|
4
|
|
135
|
use Carp (); |
|
|
4
|
|
|
|
|
7
|
|
|
|
4
|
|
|
|
|
60
|
|
|
10
|
4
|
|
|
4
|
|
15
|
use MOP::Util (); |
|
|
4
|
|
|
|
|
16
|
|
|
|
4
|
|
|
|
|
1053
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
|
13
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:STEVAN'; |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub ro : Decorator : CreateMethod { |
|
16
|
9
|
|
|
9
|
1
|
330
|
my ( $meta, $method, @args ) = @_; |
|
17
|
|
|
|
|
|
|
|
|
18
|
9
|
|
|
|
|
44
|
my $method_name = $method->name; |
|
19
|
|
|
|
|
|
|
|
|
20
|
9
|
|
|
|
|
121
|
my $slot_name; |
|
21
|
9
|
100
|
|
|
|
23
|
if ( $args[0] ) { |
|
22
|
7
|
100
|
|
|
|
26
|
if ( $args[0] eq '_' ) { |
|
23
|
1
|
|
33
|
|
|
8
|
$slot_name = '_'.(($method_name =~ /^get_(.*)$/)[0] || $method_name); |
|
24
|
|
|
|
|
|
|
} |
|
25
|
|
|
|
|
|
|
else { |
|
26
|
6
|
|
|
|
|
12
|
$slot_name = shift @args; |
|
27
|
|
|
|
|
|
|
} |
|
28
|
|
|
|
|
|
|
} |
|
29
|
|
|
|
|
|
|
else { |
|
30
|
2
|
50
|
|
|
|
8
|
if ( $method_name =~ /^get_(.*)$/ ) { |
|
31
|
0
|
|
|
|
|
0
|
$slot_name = $1; |
|
32
|
|
|
|
|
|
|
} |
|
33
|
|
|
|
|
|
|
else { |
|
34
|
2
|
|
|
|
|
5
|
$slot_name = $method_name; |
|
35
|
|
|
|
|
|
|
} |
|
36
|
|
|
|
|
|
|
} |
|
37
|
|
|
|
|
|
|
|
|
38
|
9
|
50
|
33
|
|
|
31
|
Carp::confess('Unable to build `ro` accessor for slot `' . $slot_name.'` in `'.$meta->name.'` because the slot cannot be found.') |
|
39
|
|
|
|
|
|
|
unless $meta->has_slot( $slot_name ) |
|
40
|
|
|
|
|
|
|
|| $meta->has_slot_alias( $slot_name ); |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
$meta->add_method( $method_name => sub { |
|
43
|
12
|
50
|
|
12
|
|
5773
|
Carp::confess("Cannot assign to `$slot_name`, it is a readonly") if scalar @_ != 1; |
|
|
|
|
|
3
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
44
|
12
|
|
|
|
|
71
|
$_[0]->{ $slot_name }; |
|
45
|
9
|
|
|
|
|
1367
|
}); |
|
46
|
4
|
|
|
4
|
|
34
|
} |
|
|
4
|
|
|
|
|
7
|
|
|
|
4
|
|
|
|
|
27
|
|
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub rw : Decorator : CreateMethod { |
|
49
|
2
|
|
|
2
|
1
|
52
|
my ( $meta, $method, @args ) = @_; |
|
50
|
|
|
|
|
|
|
|
|
51
|
2
|
|
|
|
|
7
|
my $method_name = $method->name; |
|
52
|
|
|
|
|
|
|
|
|
53
|
2
|
|
|
|
|
25
|
my $slot_name; |
|
54
|
2
|
100
|
|
|
|
6
|
if ( $args[0] ) { |
|
55
|
1
|
50
|
|
|
|
2
|
if ( $args[0] eq '_' ) { |
|
56
|
0
|
|
|
|
|
0
|
$slot_name = '_'.$method_name; |
|
57
|
|
|
|
|
|
|
} |
|
58
|
|
|
|
|
|
|
else { |
|
59
|
1
|
|
|
|
|
2
|
$slot_name = shift @args; |
|
60
|
|
|
|
|
|
|
} |
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
else { |
|
63
|
1
|
|
|
|
|
2
|
$slot_name = $method_name; |
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
|
|
66
|
2
|
50
|
|
|
|
7
|
Carp::confess('Unable to build `rw` accessor for slot `' . $slot_name.'` in `'.$meta->name.'` because class is immutable.') |
|
67
|
|
|
|
|
|
|
if ($meta->name)->isa('UNIVERSAL::Object::Immutable'); |
|
68
|
|
|
|
|
|
|
|
|
69
|
2
|
50
|
33
|
|
|
38
|
Carp::confess('Unable to build `rw` accessor for slot `' . $slot_name.'` in `'.$meta->name.'` because the slot cannot be found.') |
|
70
|
|
|
|
|
|
|
unless $meta->has_slot( $slot_name ) |
|
71
|
|
|
|
|
|
|
|| $meta->has_slot_alias( $slot_name ); |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
$meta->add_method( $method_name => sub { |
|
74
|
4
|
100
|
|
4
|
|
14
|
$_[0]->{ $slot_name } = $_[1] if scalar( @_ ) > 1; |
|
|
|
|
|
4
|
|
|
|
|
75
|
4
|
|
|
|
|
14
|
$_[0]->{ $slot_name }; |
|
76
|
2
|
|
|
|
|
246
|
}); |
|
77
|
4
|
|
|
4
|
|
1467
|
} |
|
|
4
|
|
|
|
|
8
|
|
|
|
4
|
|
|
|
|
27
|
|
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub wo : Decorator : CreateMethod { |
|
80
|
0
|
|
|
0
|
1
|
0
|
my ( $meta, $method, @args ) = @_; |
|
81
|
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
0
|
my $method_name = $method->name; |
|
83
|
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
0
|
my $slot_name; |
|
85
|
0
|
0
|
|
|
|
0
|
if ( $args[0] ) { |
|
86
|
0
|
0
|
|
|
|
0
|
if ( $args[0] eq '_' ) { |
|
87
|
0
|
|
0
|
|
|
0
|
$slot_name = '_'.(($method_name =~ /^set_(.*)$/)[0] || $method_name); |
|
88
|
|
|
|
|
|
|
} |
|
89
|
|
|
|
|
|
|
else { |
|
90
|
0
|
|
|
|
|
0
|
$slot_name = shift @args; |
|
91
|
|
|
|
|
|
|
} |
|
92
|
|
|
|
|
|
|
} |
|
93
|
|
|
|
|
|
|
else { |
|
94
|
0
|
0
|
|
|
|
0
|
if ( $method_name =~ /^set_(.*)$/ ) { |
|
95
|
0
|
|
|
|
|
0
|
$slot_name = $1; |
|
96
|
|
|
|
|
|
|
} |
|
97
|
|
|
|
|
|
|
else { |
|
98
|
0
|
|
|
|
|
0
|
$slot_name = $method_name; |
|
99
|
|
|
|
|
|
|
} |
|
100
|
|
|
|
|
|
|
} |
|
101
|
|
|
|
|
|
|
|
|
102
|
0
|
0
|
|
|
|
0
|
Carp::confess('Unable to build `wo` accessor for slot `' . $slot_name.'` in `'.$meta->name.'` because class is immutable.') |
|
103
|
|
|
|
|
|
|
if ($meta->name)->isa('UNIVERSAL::Object::Immutable'); |
|
104
|
|
|
|
|
|
|
|
|
105
|
0
|
0
|
0
|
|
|
0
|
Carp::confess('Unable to build `wo` accessor for slot `' . $slot_name.'` in `'.$meta->name.'` because the slot cannot be found.') |
|
106
|
|
|
|
|
|
|
unless $meta->has_slot( $slot_name ) |
|
107
|
|
|
|
|
|
|
|| $meta->has_slot_alias( $slot_name ); |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
$meta->add_method( $method_name => sub { |
|
110
|
0
|
0
|
|
0
|
|
0
|
Carp::confess("You must supply a value to write to `$slot_name`") if scalar(@_) < 1; |
|
111
|
0
|
|
|
|
|
0
|
$_[0]->{ $slot_name } = $_[1]; |
|
112
|
0
|
|
|
|
|
0
|
}); |
|
113
|
4
|
|
|
4
|
|
1336
|
} |
|
|
4
|
|
|
|
|
14
|
|
|
|
4
|
|
|
|
|
21
|
|
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub predicate : Decorator : CreateMethod { |
|
116
|
0
|
|
|
0
|
1
|
0
|
my ( $meta, $method, @args ) = @_; |
|
117
|
|
|
|
|
|
|
|
|
118
|
0
|
|
|
|
|
0
|
my $method_name = $method->name; |
|
119
|
|
|
|
|
|
|
|
|
120
|
0
|
|
|
|
|
0
|
my $slot_name; |
|
121
|
0
|
0
|
|
|
|
0
|
if ( $args[0] ) { |
|
122
|
0
|
0
|
|
|
|
0
|
if ( $args[0] eq '_' ) { |
|
123
|
0
|
|
0
|
|
|
0
|
$slot_name = '_'.(($method_name =~ /^has_(.*)$/)[0] || $method_name); |
|
124
|
|
|
|
|
|
|
} |
|
125
|
|
|
|
|
|
|
else { |
|
126
|
0
|
|
|
|
|
0
|
$slot_name = shift @args; |
|
127
|
|
|
|
|
|
|
} |
|
128
|
|
|
|
|
|
|
} |
|
129
|
|
|
|
|
|
|
else { |
|
130
|
0
|
0
|
|
|
|
0
|
if ( $method_name =~ /^has_(.*)$/ ) { |
|
131
|
0
|
|
|
|
|
0
|
$slot_name = $1; |
|
132
|
|
|
|
|
|
|
} |
|
133
|
|
|
|
|
|
|
else { |
|
134
|
0
|
|
|
|
|
0
|
$slot_name = $method_name; |
|
135
|
|
|
|
|
|
|
} |
|
136
|
|
|
|
|
|
|
} |
|
137
|
|
|
|
|
|
|
|
|
138
|
0
|
0
|
0
|
|
|
0
|
Carp::confess('Unable to build predicate for slot `' . $slot_name.'` in `'.$meta->name.'` because the slot cannot be found.') |
|
139
|
|
|
|
|
|
|
unless $meta->has_slot( $slot_name ) |
|
140
|
|
|
|
|
|
|
|| $meta->has_slot_alias( $slot_name ); |
|
141
|
|
|
|
|
|
|
|
|
142
|
0
|
|
|
0
|
|
0
|
$meta->add_method( $method_name => sub { defined $_[0]->{ $slot_name } } ); |
|
|
0
|
|
|
|
|
0
|
|
|
143
|
4
|
|
|
4
|
|
1189
|
} |
|
|
4
|
|
|
|
|
7
|
|
|
|
4
|
|
|
|
|
13
|
|
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
sub clearer : Decorator : CreateMethod { |
|
146
|
0
|
|
|
0
|
1
|
|
my ( $meta, $method, @args ) = @_; |
|
147
|
|
|
|
|
|
|
|
|
148
|
0
|
|
|
|
|
|
my $method_name = $method->name; |
|
149
|
|
|
|
|
|
|
|
|
150
|
0
|
|
|
|
|
|
my $slot_name; |
|
151
|
0
|
0
|
|
|
|
|
if ( $args[0] ) { |
|
152
|
0
|
0
|
|
|
|
|
if ( $args[0] eq '_' ) { |
|
153
|
0
|
|
0
|
|
|
|
$slot_name = '_'.(($method_name =~ /^clear_(.*)$/)[0] || $method_name); |
|
154
|
|
|
|
|
|
|
} |
|
155
|
|
|
|
|
|
|
else { |
|
156
|
0
|
|
|
|
|
|
$slot_name = shift @args; |
|
157
|
|
|
|
|
|
|
} |
|
158
|
|
|
|
|
|
|
} |
|
159
|
|
|
|
|
|
|
else { |
|
160
|
0
|
0
|
|
|
|
|
if ( $method_name =~ /^clear_(.*)$/ ) { |
|
161
|
0
|
|
|
|
|
|
$slot_name = $1; |
|
162
|
|
|
|
|
|
|
} |
|
163
|
|
|
|
|
|
|
else { |
|
164
|
0
|
|
|
|
|
|
$slot_name = $method_name; |
|
165
|
|
|
|
|
|
|
} |
|
166
|
|
|
|
|
|
|
} |
|
167
|
|
|
|
|
|
|
|
|
168
|
0
|
0
|
|
|
|
|
Carp::confess('Unable to build `clearer` accessor for slot `' . $slot_name.'` in `'.$meta->name.'` because class is immutable.') |
|
169
|
|
|
|
|
|
|
if ($meta->name)->isa('UNIVERSAL::Object::Immutable'); |
|
170
|
|
|
|
|
|
|
|
|
171
|
0
|
0
|
0
|
|
|
|
Carp::confess('Unable to build `clearer` accessor for slot `' . $slot_name.'` in `'.$meta->name.'` because the slot cannot be found.') |
|
172
|
|
|
|
|
|
|
unless $meta->has_slot( $slot_name ) |
|
173
|
|
|
|
|
|
|
|| $meta->has_slot_alias( $slot_name ); |
|
174
|
|
|
|
|
|
|
|
|
175
|
0
|
|
|
0
|
|
|
$meta->add_method( $method_name => sub { undef $_[0]->{ $slot_name } } ); |
|
|
0
|
|
|
|
|
|
|
|
176
|
4
|
|
|
4
|
|
1252
|
} |
|
|
4
|
|
|
|
|
8
|
|
|
|
4
|
|
|
|
|
14
|
|
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
1; |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
__END__ |