Skip to content

Commit 83203f5

Browse files
committed
fix improper code blocks, X<...> formatting codes.
1 parent 0f839d3 commit 83203f5

File tree

3 files changed

+51
-35
lines changed

3 files changed

+51
-35
lines changed

lib/classtut.pod

Lines changed: 41 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ It showcases custom constructors, private and public attributes, methods
77
and various aspects of signatures. It's not very much code, and yet the
88
result is interesting and, at times, useful.
99
10+
=begin code
1011
class Task {
1112
has &!callback;
1213
has Task @!dependencies;
@@ -41,27 +42,28 @@ result is interesting and, at times, useful.
4142
);
4243
4344
$eat.perform();
45+
=end code
4446
4547
=head1 Starting with class
4648
47-
X<class>
48-
X<classes>
49+
X<|class>
50+
X<|classes>
4951
50-
X<state>
51-
X<has>
52-
X<classes, has>
53-
X<behavior>
54-
X<classes, behavior>
52+
X<|state>
53+
X<|has>
54+
X<|classes, has>
55+
X<|behavior>
56+
X<|classes, behavior>
5557
5658
Perl 6, like many other languages, uses the C<class> keyword to introduce a new
5759
class. The block that follows may contain arbitrary code, just as with
5860
any other block, but classes commonly contain state and behavior declarations.
5961
The example code includes attributes (state), introduced through the C<has>
6062
keyword, and behaviors introduced through the C<method> keyword.
6163
62-
X<type object>
63-
X<defined>
64-
X<.defined>
64+
X<|type object>
65+
X<|defined>
66+
X<|.defined>
6567
6668
Declaring a class creates a I<type object> which, by default, is
6769
installed into the current package (just like a variable declared with
@@ -85,11 +87,11 @@ given object is a type object or not:
8587
8688
=head1 I can haz state?
8789
88-
X<attributes>
89-
X<classes, attributes>
90+
X<|attributes>
91+
X<|classes, attributes>
9092
91-
X<encapsulation>
92-
X<classes, encapsulation>
93+
X<|encapsulation>
94+
X<|classes, encapsulation>
9395
9496
The first three lines inside the class block all declare attributes (called
9597
I<fields> or I<instance storage> in other languages). These are storage
@@ -103,9 +105,9 @@ code to invoke in order to perform the task that an object represents:
103105
104106
has &!callback;
105107
106-
X<sigils, &>
107-
X<twigils>
108-
X<twigils, !>
108+
X<|sigils, &>
109+
X<|twigils>
110+
X<|twigils, !>
109111
110112
The C<&> sigil indicates that this attribute represents something invocable.
111113
The C<!> character is a I<twigil>, or secondary sigil. A twigil forms part of
@@ -126,10 +128,10 @@ The third attribute represents the state of completion of a task:
126128
127129
has Bool $.done;
128130
129-
X<twigils, .>
130-
X<twigils, accessors>
131-
X<accessor methods>
132-
X<classes, accessors>
131+
X<|twigils, .>
132+
X<|twigils, accessors>
133+
X<|accessor methods>
134+
X<|classes, accessors>
133135
134136
This scalar attribute (with the C<$> sigil) has a type of C<Bool>. Instead of
135137
the C<!> twigil, this twigil is C<.>. While Perl 6 does enforce encapsulation
@@ -153,15 +155,15 @@ change the attribute declaration:
153155
154156
has Bool $.done is rw;
155157
156-
X<traits, is rw>
158+
X<|traits, is rw>
157159
158160
The C<is rw> trait causes the generated accessor method to return something
159161
external code can modify to change the value of the attribute.
160162
161163
=head1 Methods
162164
163-
X<methods>
164-
X<classes, methods>
165+
X<|methods>
166+
X<|classes, methods>
165167
166168
While attributes give objects state, methods give objects behaviors. Ignore
167169
the C<new> method temporarily; it's a special type of method. Consider the
@@ -172,7 +174,7 @@ dependency list.
172174
push @!dependencies, $dependency;
173175
}
174176
175-
X<invocant>
177+
X<|invocant>
176178
177179
In many ways, this looks a lot like a C<sub> declaration. However, there are
178180
two important differences. First, declaring this routine as a method adds it to
@@ -198,7 +200,7 @@ It takes no parameters, working instead with the object's attributes. First, it
198200
checks if the task has already completed by checking the C<$!done> attribute.
199201
If so, there's nothing to do.
200202
201-
X<operators, .>
203+
X<|operators, .>
202204
203205
Otherwise, the method performs all of the task's dependencies, using the C<for>
204206
construct to iterate over all of the items in the C<@!dependencies> attribute.
@@ -217,7 +219,7 @@ task.
217219
218220
=head1 Constructors
219221
220-
X<constructors>
222+
X<|constructors>
221223
222224
Perl 6 is rather more liberal than many languages in the area of constructors.
223225
A constructor is anything that returns an instance of the class. Furthermore,
@@ -229,8 +231,8 @@ this example does:
229231
return self.bless(*, :&callback, :@dependencies);
230232
}
231233
232-
X<objects, bless>
233-
X<bless>
234+
X<|objects, bless>
235+
X<|bless>
234236
235237
The biggest difference between constructors in Perl 6 and constructors in
236238
languages such as C# and Java is that rather than setting up state on a somehow
@@ -303,6 +305,7 @@ attribute accessors.
303305
TODO: the example here is rather bad, and needs to be replaced (or much
304306
improved). See L<https://github.com/perl6/book/issues/58> for discussion.
305307
308+
=begin code
306309
class Employee {
307310
has $.salary;
308311
@@ -321,10 +324,12 @@ improved). See L<https://github.com/perl6/book/issues/58> for discussion.
321324
~ $.known_languages[0] ~ '.';
322325
}
323326
}
327+
=end code
324328
325329
Now any object of type Programmer can make use of the methods and accessors
326330
defined in the Employee class as though they were from the Programmer class.
327331
332+
=begin code
328333
my $programmer = Programmer.new(
329334
salary => 100_000,
330335
known_languages => <Perl5 Perl6 Erlang C++>,
@@ -333,13 +338,15 @@ defined in the Employee class as though they were from the Programmer class.
333338
334339
$programmer.code_to_solve('halting problem');
335340
$programmer.pay();
341+
=end code
336342
337343
=head2 Overriding Inherited Methods
338344
339345
Of course, classes can override methods and attributes defined by parent
340346
classes by defining their own. The example below demonstrates the C<Baker> class
341347
overriding the C<Cook>'s C<cook> method.
342348
349+
=begin code
343350
class Cook is Employee {
344351
has @.utensils is rw;
345352
has @.cookbooks is rw;
@@ -372,6 +379,7 @@ overriding the C<Cook>'s C<cook> method.
372379
salary => 50000);
373380
374381
$baker.cook('brioche'); # Baking a tasty brioche
382+
=end code
375383
376384
Because the dispatcher will see the C<cook> method on C<Baker> before it moves up to
377385
the parent class the C<Baker>'s C<cook> method will be called.
@@ -384,6 +392,7 @@ looking up a method to search for. As a side note, Perl 6 uses the C3
384392
algorithm to linearize the multiple inheritance hierarchies, which is a
385393
significant improvement over Perl 5's approach to handling multiple inheritance.
386394
395+
=begin code
387396
class GeekCook is Programmer is Cook {
388397
method new( *%params ) {
389398
%params<cookbooks> //= []; # remove once Rakudo fully supports autovivification
@@ -401,6 +410,7 @@ significant improvement over Perl 5's approach to handling multiple inheritance.
401410
402411
$geek.cook('pizza');
403412
$geek.code_to_solve('P =? NP');
413+
=end code
404414
405415
Now all the methods made available by both the Programmer class and the Cook
406416
class are available from the GeekCook class.
@@ -429,16 +439,13 @@ we can ask it a few questions:
429439
430440
The output can look like this:
431441
432-
=begin screen
433-
442+
=for output
434443
It's an employee
435444
Programmer()
436445
Programmer.new(known_languages => ["Perl", "Python", "Pascal"],
437446
favorite_editor => "gvim", salary => "too small")
438447
code_to_solve, known_languages, favorite_editor
439448
440-
=end screen
441-
442449
The first two tests each smart-match against a class name. If the object is
443450
of that class, or of an inheriting class, it returns true. So the object in
444451
question is of class C<Employee> or one that inherits from it, but not
@@ -464,6 +471,7 @@ is actually a method call on the I<meta class>, which is a class managing the
464471
properties of the C<Employee> class - or any other class you are interested
465472
in. This meta class enables other ways of introspection too:
466473
474+
=for code
467475
say $o.^attributes.join(', ');
468476
say $o.^parents.join(', ');
469477

lib/objects.pod

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ accessor method.
151151
152152
Methods are declared with the C<method> keyword inside of a class body.
153153
154+
=begin code
154155
class Journey {
155156
has $.origin;
156157
has $.destination;
@@ -170,6 +171,7 @@ Methods are declared with the C<method> keyword inside of a class body.
170171
"From $!origin to $!destination"
171172
}
172173
}
174+
=end code
173175
174176
A method can have a signature, just like a subroutine. Attributes can be used
175177
in methods, and can always be used with the C<!> twigil, even if they are
@@ -273,6 +275,7 @@ otherwise they break attribute initialization in subclasses. Second,
273275
C<BUILD> submethods can be used to run custom code at object construction
274276
time. They can also be used for creating aliases for attribute initialization:
275277
278+
=begin code
276279
class EncodedBuffer {
277280
has $.enc;
278281
has $.data;
@@ -285,6 +288,7 @@ time. They can also be used for creating aliases for attribute initialization:
285288
my $b1 = EncodedBuffer.new( encoding => 'UTF-8', data => [64, 65] );
286289
my $b2 = EncodedBuffer.new( enc => 'UTF-8', data => [64, 65] );
287290
# both enc and encoding are allowed now
291+
=end code
288292
289293
Since passing arguments to a routine binds the arguments to the parameters,
290294
a separate binding step is unnecessary if the attribute is used as parameter.
@@ -317,6 +321,7 @@ describing only parts of an object's behavior, and in how roles are applied to
317321
classes. Or to phrase it differently, classes are meant for managing
318322
instances, and roles are meant for managing behavior and code reuse.
319323
324+
=begin code
320325
role Serializable {
321326
method serialize() {
322327
self.perl; # very primitive serialization
@@ -334,6 +339,7 @@ instances, and roles are meant for managing behavior and code reuse.
334339
my $serialized = $p.serialize; # method provided by the role
335340
my $clone-of-p = Point.deserialization-code()($serialized);
336341
say $clone-of-p.x; # 1
342+
=end code
337343
338344
Roles are immutable as soon as the compiler parses the closing bracket of the
339345
role declaration.
@@ -381,6 +387,7 @@ When a role contains a stubbed method, a non-stubbed version of a method
381387
of the same name must be supplied at the time the role is applied to a class.
382388
This allows you to create roles that act as abstract interfaces.
383389
390+
=begin code
384391
role AbstractSerializable {
385392
method serialize() { ... } # literal ... here marks the
386393
# method as a stub
@@ -400,6 +407,7 @@ This allows you to create roles that act as abstract interfaces.
400407
has $.y;
401408
method serialize() { "p($.x, $.y)" }
402409
}
410+
=end code
403411
404412
The implementation of the stubbed method may also be provided by another role.
405413

lib/variables.pod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,13 +240,13 @@ file can be accessed via a Pod object, such as C<$=data>, C<$=SYNOPSIS> or
240240
C<=UserBlock>. That is: a variable with the same name of the desired block and a
241241
C<=> twigil.
242242
243-
=begin code
243+
=begin code
244244
=begin Foo
245245
...
246246
=end Foo
247247
248248
#after that, $=Foo gives you all Foo-Pod-blocks
249-
=end code
249+
=end code
250250
251251
You may access the Pod tree which contains all Pod structures as a hierarchical
252252
data structure through C<$=pod>.

0 commit comments

Comments
 (0)