@@ -316,7 +316,7 @@ possible to predict the moment when attribute initialization will be executed,
316
316
because it can take place during compilation, runtime or both, especially when
317
317
importing the class using the L < use|/syntax/use > keyword.
318
318
319
- = begin code :skip-test
319
+ = begin code :preamble<class Foo {}; sub some_complicated_subroutine {}>
320
320
class HaveStaticAttr {
321
321
my Foo $.foo = some_complicated_subroutine;
322
322
}
@@ -493,7 +493,7 @@ After creating a class, you can create instances of the class. Declaring a
493
493
custom constructor provides a simple way of declaring tasks along with their
494
494
dependencies. To create a single task with no dependencies, write:
495
495
496
- = for code :skip-test
496
+ = for code :preamble<class Task {}>
497
497
my $eat = Task.new({ say 'eating dinner. NOM!' });
498
498
499
499
An earlier section explained that declaring the class C < Task > installed a
@@ -505,7 +505,7 @@ modifying or accessing an existing object.
505
505
506
506
Unfortunately, dinner never magically happens. It has dependent tasks:
507
507
508
- = begin code :skip-test
508
+ = begin code :preamble<class Task {}>
509
509
my $eat =
510
510
Task.new({ say 'eating dinner. NOM!' },
511
511
Task.new({ say 'making dinner' },
@@ -523,7 +523,7 @@ Notice how the custom constructor and sensible use of whitespace makes task depe
523
523
Finally, the C < perform > method call recursively calls the C < perform > method
524
524
on the various other dependencies in order, giving the output:
525
525
526
- = begin code :skip-test
526
+ = begin code :lang<output>
527
527
making some money
528
528
going to the store
529
529
buying food
@@ -563,7 +563,7 @@ other means, such as attribute accessors.
563
563
Now, any object of type Programmer can make use of the methods and accessors
564
564
defined in the Employee class as though they were from the Programmer class.
565
565
566
- = begin code :skip-test
566
+ = begin code :preamble<class Programmer {}>
567
567
my $programmer = Programmer.new(
568
568
salary => 100_000,
569
569
known_languages => <Perl5 Perl6 Erlang C++>,
@@ -580,7 +580,7 @@ Of course, classes can override methods and attributes defined by parent
580
580
classes by defining their own. The example below demonstrates the C < Baker >
581
581
class overriding the C < Cook > 's C < cook > method.
582
582
583
- = begin code :skip-test
583
+ = begin code :preamble<class Employee {}>
584
584
class Cook is Employee {
585
585
has @.utensils is rw;
586
586
has @.cookbooks is rw;
@@ -636,7 +636,7 @@ classes when looking up a method to search for. Perl 6 uses the L<C3 algorithm
636
636
multiple inheritance hierarchies, which is better than depth-first search
637
637
for handling multiple inheritance.
638
638
639
- = begin code :skip-test
639
+ = begin code :preamble<class Programmer {}; class Cook {}>
640
640
class GeekCook is Programmer is Cook {
641
641
method new( *%params ) {
642
642
push( %params<cookbooks>, "Cooking for Geeks" );
@@ -671,7 +671,7 @@ Classes to be inherited from can be listed in the class declaration body by
671
671
prefixing the C < is > trait with C < also > . This also works for the role
672
672
composition trait C < does > .
673
673
674
- = begin code :skip-test
674
+ = begin code :preamble<class Programmer {}; class Cook {}>
675
675
class GeekCook {
676
676
also is Programmer;
677
677
also is Cook;
@@ -692,7 +692,7 @@ a controlling object) for some properties, such as its type.
692
692
Given an object C < $o > and the class definitions from the previous sections,
693
693
we can ask it a few questions:
694
694
695
- = begin code :skip-test
695
+ = begin code :preamble<my $o; class Employee {}; class GeekCook {}>
696
696
if $o ~~ Employee { say "It's an employee" };
697
697
if $o ~~ GeekCook { say "It's a geeky cook" };
698
698
say $o.perl;
@@ -702,7 +702,7 @@ we can ask it a few questions:
702
702
703
703
The output can look like this:
704
704
705
- = begin code :skip-test
705
+ = begin code :lang<output>
706
706
It's an employee
707
707
(Programmer)
708
708
Programmer.new(known_languages => ["Perl", "Python", "Pascal"],
@@ -736,7 +736,7 @@ it is actually a method call on its I<meta class>, which is a class managing
736
736
the properties of the C < Programmer > class – or any other class you are
737
737
interested in. This meta class enables other ways of introspection too:
738
738
739
- = for code :skip-test
739
+ = for code :preamble<my $o>
740
740
say $o.^attributes.join(', ');
741
741
say $o.^parents.map({ $_.^name }).join(', ');
742
742
0 commit comments