Skip to content

Commit 990083c

Browse files
committed
Changes anchors, decapitalizes headers, and reflows
Refs #2223 #1303
1 parent cff167a commit 990083c

File tree

1 file changed

+31
-19
lines changed

1 file changed

+31
-19
lines changed

doc/Language/classtut.pod6

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
=begin pod :tag<tutorial>
22
3-
=TITLE Classes and Objects
3+
=TITLE Classes and objects
44
55
=SUBTITLE A tutorial about creating and using classes in Perl 6
66
@@ -148,9 +148,9 @@ X<|type object>
148148
X<|DEFINITE>
149149
X<|.DEFINITE>
150150
151-
Declaring a class creates a new I<type object> which, by default, is installed into
152-
the current package (just like a variable declared with C<our> scope). This
153-
type object is an "empty instance" of the class. For example, types such as
151+
Declaring a class creates a new I<type object> which, by default, is installed
152+
into the current package (just like a variable declared with C<our> scope).
153+
This type object is an "empty instance" of the class. For example, types such as
154154
C<Int> and C<Str> refer to the type object of one of the Perl 6 built-in
155155
classes. The example above uses the class name C<Task> so that other code can
156156
refer to it later, such as to create class instances by calling the C<new>
@@ -261,7 +261,12 @@ has Task @!dependencies;
261261
has $.ready = not @!dependencies;
262262
263263
X<|class variables>
264-
A class declaration can also include I<class variables>, which are variables that are shared by all instances, and can be used for things like counting the number of instantiations or any other shared state. Class variables use the same syntax as the rest of the attributes, but are declared as C<my> or C<our>, depending on the scope; the second type of variables will be used across the class hierarchy.
264+
A class declaration can also include I<class variables>, which are variables
265+
that are shared by all instances, and can be used for things like counting the
266+
number of instantiations or any other shared state. Class variables use the same
267+
syntax as the rest of the attributes, but are declared as C<my> or C<our>,
268+
depending on the scope; the second type of variables will be used across the
269+
class hierarchy.
265270
266271
=begin code
267272
class Str-with-ID is Str {
@@ -304,11 +309,11 @@ that a module can, so making a scoped variable sounds like good idea.
304309
305310
=end code
306311
307-
Class attributes defined by L<my|/syntax/my> or L<our|/syntax/our> may also be initialized when
308-
being declared, however we are implementing the Singleton pattern here and
309-
the object must be created during its first use. It is not 100% possible to
310-
predict the moment when attribute initialization will be executed, because
311-
it can take place during compilation, runtime or both, especially when
312+
Class attributes defined by L<my|/syntax/my> or L<our|/syntax/our> may also be
313+
initialized when being declared, however we are implementing the Singleton
314+
pattern here and the object must be created during its first use. It is not 100%
315+
possible to predict the moment when attribute initialization will be executed,
316+
because it can take place during compilation, runtime or both, especially when
312317
importing the class using the L<use|/syntax/use> keyword.
313318
314319
=begin code :skip-test
@@ -365,7 +370,6 @@ it checks if the task has already completed by checking the C<$!done>
365370
attribute. If so, there's nothing to do.
366371
367372
X<|operators,.>
368-
369373
Otherwise, the method performs all of the task's dependencies, using the
370374
C<for> construct to iterate over all of the items in the C<@!dependencies>
371375
attribute. This iteration places each item – each a C<Task> object – into
@@ -382,15 +386,15 @@ on this object (if this C<Task> is a dependency of another C<Task>, for
382386
example) will not repeat the task.
383387
384388
X<|! (private methods)>
385-
=head2 Private Methods
389+
=head2 Private methods
386390
387391
Just like attributes, methods can also be private. Private methods are declared
388392
with a prefixed exclamation mark. They are called with C<self!> followed by the
389393
method's name. To call a private method of another class the calling class has
390394
to be trusted by the called class. A trust relationship is declared with
391395
C<trusts> and the class to be trusted must already be declared. Calling a
392-
private method of another class requires an instance of that class and the
393-
fully qualified name of the method. Trust also allows access to private attributes.
396+
private method of another class requires an instance of that class and the fully
397+
qualified name of the method. Trust also allows access to private attributes.
394398
395399
class B {...}
396400
@@ -417,9 +421,8 @@ fully qualified name of the method. Trust also allows access to private attribu
417421
Trust relationships are not subject to inheritance. To trust the global
418422
namespace, the pseudo package C<GLOBAL> can be used.
419423
420-
=head1 Constructors
421-
422424
X<|constructors>
425+
=head1 Constructors
423426
424427
Perl 6 is rather more liberal than many languages in the area of
425428
constructors. A constructor is anything that returns an instance of the
@@ -753,7 +756,11 @@ find out via introspection.
753756
754757
=head2 X<Overriding default gist method>
755758
756-
Some classes might need its own version of C<gist>, which overrides the terse way it is printed when called to provide a default representation of the class. For instance, L<exceptions|/language/exceptions#Uncaught_Exceptions> might want to write just the C<payload> and not the full object so that it is clearer what has happened. But you can do that with every class:
759+
Some classes might need its own version of C<gist>, which overrides the terse
760+
way it is printed when called to provide a default representation of the class.
761+
For instance, L<exceptions|/language/exceptions#Uncaught_Exceptions> might want
762+
to write just the C<payload> and not the full object so that it is clearer what
763+
has happened. But you can do that with every class:
757764
758765
=begin code
759766
class Cook {
@@ -769,7 +776,9 @@ class Cook {
769776
}
770777
771778
multi method gist(Cook:U:) { '⚗' ~ self.^name ~ '⚗' }
772-
multi method gist(Cook:D:) { '⚗ Cooks with ' ~ @.utensils.join( " ‣ ") ~ ' using ' ~ @.cookbooks.map( "«" ~ * ~ "»").join( " and ") }
779+
multi method gist(Cook:D:) {
780+
'⚗ Cooks with ' ~ @.utensils.join( " ‣ ") ~ ' using '
781+
~ @.cookbooks.map( "«" ~ * ~ "»").join( " and ") }
773782
}
774783
775784
my $cook = Cook.new(
@@ -780,7 +789,10 @@ say Cook.gist; # OUTPUT: «⚗Cook⚗»
780789
say $cook.gist; # OUTPUT: «⚗ Cooks with spoon ‣ ladle ‣ knife ‣ pan using «Cooking for geeks» and «The French Chef Cookbook»␤»
781790
=end code
782791
783-
Usually you will want to define two methods, one for the class and another for instances; in this case, the class method uses the alembic symbol, and the instance method, defined below, aggregates the data we have on the cook to show it in a narrative way.
792+
Usually you will want to define two methods, one for the class and another for
793+
class instances; in this case, the class method uses the alembic symbol, and the
794+
instance method, defined below, aggregates the data we have on the cook to show
795+
it in a narrative way.
784796
785797
=end pod
786798

0 commit comments

Comments
 (0)