| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Class::Plain 0.04; |
|
2
|
|
|
|
|
|
|
|
|
3
|
7
|
|
|
7
|
|
386566
|
use v5.16; |
|
|
7
|
|
|
|
|
73
|
|
|
4
|
7
|
|
|
7
|
|
35
|
use warnings; |
|
|
7
|
|
|
|
|
11
|
|
|
|
7
|
|
|
|
|
187
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
7
|
|
|
7
|
|
29
|
use Carp; |
|
|
7
|
|
|
|
|
11
|
|
|
|
7
|
|
|
|
|
379
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
7
|
|
|
7
|
|
34
|
use mro; |
|
|
7
|
|
|
|
|
18
|
|
|
|
7
|
|
|
|
|
64
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
7
|
|
|
7
|
0
|
3856
|
sub dl_load_flags { 0x01 } |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
require DynaLoader; |
|
13
|
|
|
|
|
|
|
__PACKAGE__->DynaLoader::bootstrap( our $VERSION ); |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $XSAPI_VERSION = "0.48"; |
|
16
|
|
|
|
|
|
|
|
|
17
|
7
|
|
|
7
|
|
3059
|
use Class::Plain::Base; |
|
|
7
|
|
|
|
|
18
|
|
|
|
7
|
|
|
|
|
1370
|
|
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub import { |
|
20
|
10
|
|
|
10
|
|
6230
|
my $class = shift; |
|
21
|
10
|
|
|
|
|
23
|
my $caller = caller; |
|
22
|
|
|
|
|
|
|
|
|
23
|
10
|
|
|
|
|
27
|
my %syms = map { $_ => 1 } @_; |
|
|
0
|
|
|
|
|
0
|
|
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# Default imports |
|
26
|
10
|
50
|
|
|
|
37
|
unless( %syms ) { |
|
27
|
10
|
|
|
|
|
53
|
$syms{$_}++ for qw(class method field); |
|
28
|
|
|
|
|
|
|
} |
|
29
|
|
|
|
|
|
|
|
|
30
|
10
|
|
50
|
|
|
144
|
delete $syms{$_} and $^H{"Class::Plain/$_"}++ for qw( class method field); |
|
31
|
|
|
|
|
|
|
|
|
32
|
10
|
50
|
|
|
|
5816
|
croak "Unrecognised import symbols @{[ keys %syms ]}" if keys %syms; |
|
|
0
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
} |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=encoding UTF-8 |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 Name |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
C - a class syntax for the hash-based Perl OO. |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head1 Usage |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
use Class::Plain; |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
class Point { |
|
46
|
|
|
|
|
|
|
field x : reader; |
|
47
|
|
|
|
|
|
|
field y : reader; |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
method new : common { |
|
50
|
|
|
|
|
|
|
my $self = $class->SUPER::new(@_); |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
$self->{x} //= 0; |
|
53
|
|
|
|
|
|
|
$self->{y} //= 0; |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
return $self; |
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
method move { |
|
59
|
|
|
|
|
|
|
my ($x, $y) = @_; |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
$self->{x} += $x; |
|
62
|
|
|
|
|
|
|
$self->{y} += $y; |
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
method to_string { |
|
66
|
|
|
|
|
|
|
return "($self->{x},$self->{y})"; |
|
67
|
|
|
|
|
|
|
} |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
my $point = Point->new(x => 5, y => 10); |
|
71
|
|
|
|
|
|
|
print $point->x . "\n"; |
|
72
|
|
|
|
|
|
|
print $point->y . "\n"; |
|
73
|
|
|
|
|
|
|
print $point->to_string . "\n"; |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
Inheritance: |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
class Point3D : isa(Point) { |
|
78
|
|
|
|
|
|
|
field z : reader; |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
method new : common { |
|
81
|
|
|
|
|
|
|
my $self = $class->SUPER::new(@_); |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
$self->{z} //= 0; |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
return $self; |
|
86
|
|
|
|
|
|
|
} |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
method move { |
|
89
|
|
|
|
|
|
|
my ($x, $y, $z) = @_; |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
$self->SUPER::move($x, $y); |
|
92
|
|
|
|
|
|
|
$self->{z} += $z; |
|
93
|
|
|
|
|
|
|
} |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
method to_string { |
|
96
|
|
|
|
|
|
|
return "($self->{x},$self->{y},$self->{z})"; |
|
97
|
|
|
|
|
|
|
} |
|
98
|
|
|
|
|
|
|
} |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
my $point3d = Point3D->new(x => 5, y => 10, z => 15); |
|
101
|
|
|
|
|
|
|
print $point3d->x . "\n"; |
|
102
|
|
|
|
|
|
|
print $point3d->y . "\n"; |
|
103
|
|
|
|
|
|
|
print $point3d->z . "\n"; |
|
104
|
|
|
|
|
|
|
print $point3d->to_string . "\n"; |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
See also L. |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 Description |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
This module provides a class syntax for the hash-based Perl OO. |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 Keywords |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head2 class |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
class NAME { ... } |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
class NAME : ATTRS... { |
|
119
|
|
|
|
|
|
|
... |
|
120
|
|
|
|
|
|
|
} |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
class NAME; |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
class NAME : ATTRS...; |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
Behaves similarly to the C keyword, but provides a package that |
|
127
|
|
|
|
|
|
|
defines a new class. |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
As with C, an optional block may be provided. If so, the contents of |
|
130
|
|
|
|
|
|
|
that block define the new class and the preceding package continues |
|
131
|
|
|
|
|
|
|
afterwards. If not, it sets the class as the package context of following |
|
132
|
|
|
|
|
|
|
keywords and definitions. |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
The following class attributes are supported: |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head3 isa Attribute |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
# The single inheritance |
|
139
|
|
|
|
|
|
|
: isa(SUPER_CLASS) |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
# The multiple inheritance |
|
142
|
|
|
|
|
|
|
: isa(SUPER_CLASS1) isa(SUPER_CLASS2) |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
# The super class is nothing |
|
145
|
|
|
|
|
|
|
: isa() |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
Define a supper classes that this class extends. |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
If the supper class is not specified by C attribute, the class inherits L. |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
The super class is added to the end of C<@ISA>. |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
If the the super class name doesn't exists in the Perl's symbol table, the super class is loaded. |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
Otherwise if the super class doesn't have the C method and doesn't have the class names in C<@ISA>, the super class is loaded. |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head2 field |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
field NAME; |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
field NAME : ATTR ATTR...; |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
Define fields. |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
The following field attributes are supported: |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=head3 reader Attribute |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
: reader |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
: reader(METHOD_NAME) |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
Generates a reader method to return the current value of the field. If no name |
|
174
|
|
|
|
|
|
|
is given, the name of the field is used. |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
field x : reader; |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
# This is the same as the following code. |
|
179
|
|
|
|
|
|
|
method x { |
|
180
|
|
|
|
|
|
|
$self->{x}; |
|
181
|
|
|
|
|
|
|
} |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
The different method name can be specified. |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
field x : reader(x_different_name); |
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=head3 writer Attribute |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
: writer |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
: writer(METHOD_NAME) |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
Generates a writer method to set a new value of the field from its arguments. |
|
194
|
|
|
|
|
|
|
If no name is given, the name of the field is used prefixed by C. |
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
field x : writer; |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
# This is the same as the following code. |
|
199
|
|
|
|
|
|
|
method set_x { |
|
200
|
|
|
|
|
|
|
$self->{x} = shift; |
|
201
|
|
|
|
|
|
|
return $self; |
|
202
|
|
|
|
|
|
|
} |
|
203
|
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
The different method name can be specified. |
|
205
|
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
field x : writer(set_x_different_name); |
|
207
|
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=head3 rw Attribute |
|
209
|
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
: rw |
|
211
|
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
: rw(METHOD_NAME) |
|
213
|
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
Generates a read-write method to set and get the value of the field. |
|
215
|
|
|
|
|
|
|
If no name is given, the name of the field is used. |
|
216
|
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
field x : rw; |
|
218
|
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
# This is the same as the following code. |
|
220
|
|
|
|
|
|
|
method x { |
|
221
|
|
|
|
|
|
|
if (@_) { |
|
222
|
|
|
|
|
|
|
$self->{x} = shift; |
|
223
|
|
|
|
|
|
|
return $self; |
|
224
|
|
|
|
|
|
|
} |
|
225
|
|
|
|
|
|
|
$self->{x}; |
|
226
|
|
|
|
|
|
|
} |
|
227
|
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
The different method name can be specified. |
|
229
|
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
field x : rw(x_different_name); |
|
231
|
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
=head2 method |
|
233
|
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
method NAME { |
|
235
|
|
|
|
|
|
|
... |
|
236
|
|
|
|
|
|
|
} |
|
237
|
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
method NAME : ATTR ATTR ... { |
|
239
|
|
|
|
|
|
|
... |
|
240
|
|
|
|
|
|
|
} |
|
241
|
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
Define a new named method. This behaves similarly to the C keyword. |
|
243
|
|
|
|
|
|
|
In addition, the method body will have a lexical called C<$self> |
|
244
|
|
|
|
|
|
|
which contains the invocant object directly; it will already have been shifted |
|
245
|
|
|
|
|
|
|
from the C<@_> array. |
|
246
|
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
The following method attributes are supported. |
|
248
|
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
B |
|
250
|
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
# An instance method |
|
252
|
|
|
|
|
|
|
method to_string { |
|
253
|
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
my $string = "($self->{x},$self->{y})"; |
|
255
|
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
return $string; |
|
257
|
|
|
|
|
|
|
} |
|
258
|
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
=head3 common Attribute |
|
260
|
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
: common |
|
262
|
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
Marks that this method is a class-common method, instead of a regular instance |
|
264
|
|
|
|
|
|
|
method. A class-common method may be invoked on class names instead of |
|
265
|
|
|
|
|
|
|
instances. Within the method body there is a lexical C<$class> available instead of C<$self>. |
|
266
|
|
|
|
|
|
|
It will already have been shifted from the C<@_> array. |
|
267
|
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
B |
|
269
|
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
# A class method |
|
271
|
|
|
|
|
|
|
method new : common { |
|
272
|
|
|
|
|
|
|
my $self = $class->SUPER::new(@_); |
|
273
|
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
# ... |
|
275
|
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
return $self; |
|
277
|
|
|
|
|
|
|
} |
|
278
|
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
=head1 Required Perl Version |
|
280
|
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
Perl 5.16+. |
|
282
|
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
=head1 Subroutine Signatures Support |
|
284
|
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
C> supports the L from C. |
|
286
|
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
The L was supported from C, |
|
288
|
|
|
|
|
|
|
but the parser L used in C can parse only the subroutine signatures after C. |
|
289
|
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
use feature 'signatures'; |
|
291
|
|
|
|
|
|
|
|
|
292
|
|
|
|
|
|
|
use Class::Plain; |
|
293
|
|
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
Class Point { |
|
295
|
|
|
|
|
|
|
|
|
296
|
|
|
|
|
|
|
# ... |
|
297
|
|
|
|
|
|
|
|
|
298
|
|
|
|
|
|
|
method move($x = 0, $y = 0) { |
|
299
|
|
|
|
|
|
|
$self->{x} += $x; |
|
300
|
|
|
|
|
|
|
$self->{y} += $y; |
|
301
|
|
|
|
|
|
|
} |
|
302
|
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
# ... |
|
304
|
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
} |
|
306
|
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
=head1 Cookbook |
|
308
|
|
|
|
|
|
|
|
|
309
|
|
|
|
|
|
|
Exmples of C. |
|
310
|
|
|
|
|
|
|
|
|
311
|
|
|
|
|
|
|
L |
|
312
|
|
|
|
|
|
|
|
|
313
|
|
|
|
|
|
|
=head1 See Also |
|
314
|
|
|
|
|
|
|
|
|
315
|
|
|
|
|
|
|
=head2 Object::Pad |
|
316
|
|
|
|
|
|
|
|
|
317
|
|
|
|
|
|
|
The implementation of the C module is started from the copy of the source code of L. |
|
318
|
|
|
|
|
|
|
|
|
319
|
|
|
|
|
|
|
=head2 Corinna |
|
320
|
|
|
|
|
|
|
|
|
321
|
|
|
|
|
|
|
C uses the keywords and attributes that are specified in L. |
|
322
|
|
|
|
|
|
|
|
|
323
|
|
|
|
|
|
|
The keywords: C, C, C. |
|
324
|
|
|
|
|
|
|
|
|
325
|
|
|
|
|
|
|
The attributes: C, C, C, C. |
|
326
|
|
|
|
|
|
|
|
|
327
|
|
|
|
|
|
|
Only the C attribute is got from L, L, L. |
|
328
|
|
|
|
|
|
|
|
|
329
|
|
|
|
|
|
|
=head2 XS::Parse::Keyword |
|
330
|
|
|
|
|
|
|
|
|
331
|
|
|
|
|
|
|
The C and C keywords are parsed by L. |
|
332
|
|
|
|
|
|
|
|
|
333
|
|
|
|
|
|
|
=head2 XS::Parse::Sublike |
|
334
|
|
|
|
|
|
|
|
|
335
|
|
|
|
|
|
|
The C keyword is parsed by L. |
|
336
|
|
|
|
|
|
|
|
|
337
|
|
|
|
|
|
|
=head1 Repository |
|
338
|
|
|
|
|
|
|
|
|
339
|
|
|
|
|
|
|
L |
|
340
|
|
|
|
|
|
|
|
|
341
|
|
|
|
|
|
|
=head1 Author |
|
342
|
|
|
|
|
|
|
|
|
343
|
|
|
|
|
|
|
Yuki Kimoto Ekimoto.yuki@gmail.comE |
|
344
|
|
|
|
|
|
|
|
|
345
|
|
|
|
|
|
|
=head1 Copyright & LICENSE |
|
346
|
|
|
|
|
|
|
|
|
347
|
|
|
|
|
|
|
Copyright 2022-2022 Yuki Kimoto, all rights reserved. |
|
348
|
|
|
|
|
|
|
|
|
349
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
|
350
|
|
|
|
|
|
|
under the same terms as Perl itself. |
|
351
|
|
|
|
|
|
|
|
|
352
|
|
|
|
|
|
|
=cut |
|
353
|
|
|
|
|
|
|
|
|
354
|
|
|
|
|
|
|
1; |