Skip to content

Commit

Permalink
Changes anchors, decapitalizes headers, and reflows
Browse files Browse the repository at this point in the history
Refs #2223 #1303
  • Loading branch information
JJ committed Jul 30, 2018
1 parent cff167a commit 990083c
Showing 1 changed file with 31 additions and 19 deletions.
50 changes: 31 additions & 19 deletions doc/Language/classtut.pod6
@@ -1,6 +1,6 @@
=begin pod :tag<tutorial>
=TITLE Classes and Objects
=TITLE Classes and objects
=SUBTITLE A tutorial about creating and using classes in Perl 6
Expand Down Expand Up @@ -148,9 +148,9 @@ X<|type object>
X<|DEFINITE>
X<|.DEFINITE>
Declaring a class creates a new I<type object> which, by default, is installed into
the current package (just like a variable declared with C<our> scope). This
type object is an "empty instance" of the class. For example, types such as
Declaring a class creates a new I<type object> which, by default, is installed
into the current package (just like a variable declared with C<our> scope).
This type object is an "empty instance" of the class. For example, types such as
C<Int> and C<Str> refer to the type object of one of the Perl 6 built-in
classes. The example above uses the class name C<Task> so that other code can
refer to it later, such as to create class instances by calling the C<new>
Expand Down Expand Up @@ -261,7 +261,12 @@ has Task @!dependencies;
has $.ready = not @!dependencies;
X<|class variables>
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.
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.
=begin code
class Str-with-ID is Str {
Expand Down Expand Up @@ -304,11 +309,11 @@ that a module can, so making a scoped variable sounds like good idea.
=end code
Class attributes defined by L<my|/syntax/my> or L<our|/syntax/our> may also be initialized when
being declared, however we are implementing the Singleton pattern here and
the object must be created during its first use. It is not 100% possible to
predict the moment when attribute initialization will be executed, because
it can take place during compilation, runtime or both, especially when
Class attributes defined by L<my|/syntax/my> or L<our|/syntax/our> may also be
initialized when being declared, however we are implementing the Singleton
pattern here and the object must be created during its first use. It is not 100%
possible to predict the moment when attribute initialization will be executed,
because it can take place during compilation, runtime or both, especially when
importing the class using the L<use|/syntax/use> keyword.
=begin code :skip-test
Expand Down Expand Up @@ -365,7 +370,6 @@ it checks if the task has already completed by checking the C<$!done>
attribute. If so, there's nothing to do.
X<|operators,.>
Otherwise, the method performs all of the task's dependencies, using the
C<for> construct to iterate over all of the items in the C<@!dependencies>
attribute. This iteration places each item – each a C<Task> object – into
Expand All @@ -382,15 +386,15 @@ on this object (if this C<Task> is a dependency of another C<Task>, for
example) will not repeat the task.
X<|! (private methods)>
=head2 Private Methods
=head2 Private methods
Just like attributes, methods can also be private. Private methods are declared
with a prefixed exclamation mark. They are called with C<self!> followed by the
method's name. To call a private method of another class the calling class has
to be trusted by the called class. A trust relationship is declared with
C<trusts> and the class to be trusted must already be declared. Calling a
private method of another class requires an instance of that class and the
fully qualified name of the method. Trust also allows access to private attributes.
private method of another class requires an instance of that class and the fully
qualified name of the method. Trust also allows access to private attributes.
class B {...}
Expand All @@ -417,9 +421,8 @@ fully qualified name of the method. Trust also allows access to private attribu
Trust relationships are not subject to inheritance. To trust the global
namespace, the pseudo package C<GLOBAL> can be used.
=head1 Constructors
X<|constructors>
=head1 Constructors
Perl 6 is rather more liberal than many languages in the area of
constructors. A constructor is anything that returns an instance of the
Expand Down Expand Up @@ -753,7 +756,11 @@ find out via introspection.
=head2 X<Overriding default gist method>
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:
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:
=begin code
class Cook {
Expand All @@ -769,7 +776,9 @@ class Cook {
}
multi method gist(Cook:U:) { '⚗' ~ self.^name ~ '⚗' }
multi method gist(Cook:D:) { '⚗ Cooks with ' ~ @.utensils.join( " ‣ ") ~ ' using ' ~ @.cookbooks.map( "«" ~ * ~ "»").join( " and ") }
multi method gist(Cook:D:) {
'⚗ Cooks with ' ~ @.utensils.join( " ‣ ") ~ ' using '
~ @.cookbooks.map( "«" ~ * ~ "»").join( " and ") }
}
my $cook = Cook.new(
Expand All @@ -780,7 +789,10 @@ say Cook.gist; # OUTPUT: «⚗Cook⚗»
say $cook.gist; # OUTPUT: «⚗ Cooks with spoon ‣ ladle ‣ knife ‣ pan using «Cooking for geeks» and «The French Chef Cookbook»␤»
=end code
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.
Usually you will want to define two methods, one for the class and another for
class 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.
=end pod

Expand Down

0 comments on commit 990083c

Please sign in to comment.