@@ -37,13 +37,11 @@ In the two classes, the default constructor is being used. This
37
37
constructor will use named parameters in its invocation: C « Point.new(x =>
38
38
0, y => 0) » .
39
39
40
- X < |Submethod >
41
- You can also provide your own construction and C < BUILD >
42
- implementation. The following, more elaborate example shows how a
43
- dependency handler might look in Perl 6. It showcases custom
44
- constructors, private and public attributes, L < Submethod|/type/Submethod > s, methods, and
45
- various aspects of signatures. It's not a lot of code, and yet the
46
- result is interesting and useful.
40
+ You can also provide your own construction and C < BUILD > implementation. The
41
+ following, more elaborate example shows how a dependency handler might look in
42
+ Perl 6. It showcases custom constructors, private and public attributes,
43
+ L < Submethod|/type/Submethod > s, methods, and various aspects of signatures. It's
44
+ not a lot of code, and yet the result is interesting and useful.
47
45
48
46
= begin code
49
47
class Task {
@@ -296,18 +294,16 @@ to do this.
296
294
Perl 6 has no B < static > keyword. Nevertheless, any class may declare anything
297
295
that a module can, so making a scoped variable sounds like good idea.
298
296
299
- = begin code
300
-
301
- class Singleton {
302
- my Singleton $instance;
303
- method new {!!!}
304
- submethod instance {
305
- $instance = Singleton.bless unless $instance;
306
- $instance;
307
- }
297
+ = begin code
298
+ class Singleton {
299
+ my Singleton $instance;
300
+ method new {!!!}
301
+ submethod instance {
302
+ $instance = Singleton.bless unless $instance;
303
+ $instance;
308
304
}
309
-
310
- = end code
305
+ }
306
+ = end code
311
307
312
308
Class attributes defined by L < my|/syntax/my > or L < our|/syntax/our > may also be
313
309
initialized when being declared, however we are implementing the Singleton
@@ -316,11 +312,11 @@ possible to predict the moment when attribute initialization will be executed,
316
312
because it can take place during compilation, runtime or both, especially when
317
313
importing the class using the L < use|/syntax/use > keyword.
318
314
319
- = begin code :preamble<class Foo {}; sub some_complicated_subroutine {}>
320
- class HaveStaticAttr {
321
- my Foo $.foo = some_complicated_subroutine;
322
- }
323
- = end code
315
+ = begin code :preamble<class Foo {}; sub some_complicated_subroutine {}>
316
+ class HaveStaticAttr {
317
+ my Foo $.foo = some_complicated_subroutine;
318
+ }
319
+ = end code
324
320
325
321
Class attributes may also be declared with a secondary sigil – in a similar
326
322
manner to object attributes – that will generate read-only accessors if the
@@ -795,4 +791,4 @@ it in a narrative way.
795
791
796
792
= end pod
797
793
798
- # vim: expandtab softtabstop=4 shiftwidth=4 ft=perl6
794
+ # vim: expandtab softtabstop=4 shiftwidth=4 ft=perl6
0 commit comments