This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Remove two spaces after periods to keep the document consistent
[perl5.git] / pod / perlootut.pod
index e25bb77..6f373a2 100644 (file)
@@ -67,9 +67,9 @@ since the beginning of the epoch.
 The methods associated with a file might include C<rename()> and
 C<write()>.
 
-In Perl most objects are hash references, but the OO systems we
-recommend keep you from having to worry about this. In practice, it's
-best to consider an object's internal data structure opaque.
+In Perl most objects are hashes, but the OO systems we recommend keep
+you from having to worry about this. In practice, it's best to consider
+an object's internal data structure opaque.
 
 =head2 Class
 
@@ -104,16 +104,17 @@ later.)
 
 =head3 Blessing
 
-As we said earlier, most Perl objects are hash references, but an
-object can be a reference to any Perl data type (scalar, array, etc.).
-Turning a plain reference into an object is done by B<blessing> that
-reference using Perl's C<bless> function.
+As we said earlier, most Perl objects are hashes, but an object can be
+an instance of any Perl data type (scalar, array, etc.). Turning a
+plain data structure into an object is done by B<blessing> that data
+structure using Perl's C<bless> function.
 
 While we strongly suggest you don't build your objects from scratch,
-you should know the term B<bless>. A B<blessed> reference is an object.
-We sometimes say that an object has been "blessed into a class".
+you should know the term B<bless>. A B<blessed> data structure (aka "a
+referent") is an object. We sometimes say that an object has been
+"blessed into a class".
 
-Once a reference has been blessed, the C<blessed> function from the
+Once a referent has been blessed, the C<blessed> function from the
 L<Scalar::Util> core module can tell us its class name. This subroutine
 returns an object's class when passed an object, and false otherwise.
 
@@ -135,7 +136,8 @@ their constructor:
 
 You already learned that a B<method> is a subroutine that operates on
 an object. You can think of a method as the things that an object can
-I<do>.
+I<do>. If an object is a noun, then methods are its verbs (save, print,
+open).
 
 In Perl, methods are simply subroutines that live in a class's package.
 Methods are always written to receive the object as their first
@@ -147,7 +149,7 @@ argument:
       print "This file is at ", $self->path, "\n";
   }
 
-  $larry->print_path;
+  $file->print_info;
   # The file is at /etc/hostname
 
 What makes a method special is I<how it's called>. The arrow operator
@@ -165,7 +167,7 @@ name or an object. We can also pass additional arguments to the method:
       print $prefix, ", ", $self->path, "\n";
   }
 
-  $larry->print_info("The file is located at ");
+  $file->print_info("The file is located at ");
   # The file is located at /etc/hostname
 
 =head2 Attributes
@@ -175,7 +177,7 @@ we assign values to those attributes. For example, every C<File> object
 has a path. Attributes are sometimes called B<properties>.
 
 Perl has no special syntax for attributes. Under the hood, attributes
-are often stored as keys in the object's hash reference, but don't
+are often stored as keys in the object's underlying hash, but don't
 worry about this.
 
 We recommend that you only access attributes via B<accessor> methods.
@@ -216,8 +218,8 @@ Polymorphism is one of the key concepts of object-oriented design.
 =head2 Inheritance
 
 B<Inheritance> lets you create a specialized version of an existing
-class. Inheritance lets the new class to reuse the methods and
-attributes of another class.
+class. Inheritance lets the new class reuse the methods and attributes of
+another class.
 
 For example, we could create an C<File::MP3> class which B<inherits>
 from C<File>. An C<File::MP3> B<is-a> I<more specific> type of C<File>.
@@ -331,13 +333,12 @@ that its parent class uses. In reality, subclassing sometimes involves
 violating encapsulation, but a good API can minimize the need to do
 this.
 
-We mentioned earlier that most Perl objects are implemented as hash
-references under the hood. The principle of encapsulation tells us that
-we should not rely on this. Instead, we should use accessor methods to
-access the data in that hash reference. The object systems that we
-recommend below all automate the generation of accessor methods. If you
-use one of them, you should never have to access the object as a hash
-reference directly.
+We mentioned earlier that most Perl objects are implemented as hashes
+under the hood. The principle of encapsulation tells us that we should
+not rely on this. Instead, we should use accessor methods to access the
+data in that hash. The object systems that we recommend below all
+automate the generation of accessor methods. If you use one of them,
+you should never have to access the object as a hash directly.
 
 =head2 Composition
 
@@ -463,9 +464,6 @@ Little, and draws heavily from his work on the Perl 6 OO design.
 
 Here is our C<File> class using C<Moose>:
 
-
-Here's a simple but complete C<Moose> class:
-
   package File;
   use Moose;
 
@@ -578,27 +576,20 @@ compiler. If you need to install your software on a system without a
 compiler, or if having I<any> dependencies is a problem, then C<Moose>
 may not be right for you.
 
-=head3 Mouse
+=head3 Moo
 
 If you try C<Moose> and find that one of these issues is preventing you
-from using C<Moose>, we encourage you to consider L<Mouse> next.
-C<Mouse> implements a subset of C<Moose>'s functionality in a simpler
-package. For all features that it does implement, the end-user API is
-I<identical> to C<Moose>, meaning you can switch from C<Mouse> to
+from using C<Moose>, we encourage you to consider L<Moo> next.
+C<Moo> implements a subset of C<Moose>'s functionality in a simpler
+package. For most features that it does implement, the end-user API is
+I<identical> to C<Moose>, meaning you can switch from C<Moo> to
 C<Moose> quite easily.
 
-C<Mouse> does not implement most of C<Moose>'s introspection API, so
-it's often faster when loading your modules. Additionally, all of its
-I<required> dependencies ship with the Perl core, and it can run
-without a compiler. If you do have a compiler, C<Mouse> will use it to
-compile some of its code for a speed boost.
-
-Finally, it ships with a C<Mouse::Tiny> module that takes most of
-C<Mouse>'s features and bundles them up in a single module file. You
-can copy this module file into your application's library directory for
-easy bundling.
+C<Moo> does not implement most of C<Moose>'s introspection API, so it's often
+faster when loading your modules. Additionally, none of its dependencies
+require XS, so it can be installed on machines without a compiler.
 
-The C<Moose> authors hope that one day C<Mouse> can be made obsolete by
+The C<Moose> authors hope that one day C<Moo> can be made obsolete by
 improving C<Moose> enough, but for now it provides a worthwhile
 alternative to C<Moose>.
 
@@ -685,8 +676,8 @@ Here's a brief recap of the options we covered:
 =item * L<Moose>
 
 C<Moose> is the maximal option. It has a lot of features, a big
-ecosystem, and a thriving user base. We also covered L<Mouse> briefly.
-C<Mouse> is C<Moose> lite, and a reasonable alternative when Moose
+ecosystem, and a thriving user base. We also covered L<Moo> briefly.
+C<Moo> is C<Moose> lite, and a reasonable alternative when Moose
 doesn't work for your application.
 
 =item * L<Class::Accessor>
@@ -725,10 +716,10 @@ built-in OO works.
 
 =head1 CONCLUSION
 
-As we said before, Perl's minimal OO system has lead to a flourishing
-of OO systems on CPAN. While you can still drop down to the bare metal
-and write your classes by hand, there's really no reason to do that in
-2011.
+As we said before, Perl's minimal OO system has led to a profusion of
+OO systems on CPAN. While you can still drop down to the bare metal and
+write your classes by hand, there's really no reason to do that with
+modern Perl.
 
 For small systems, L<Object::Tiny> and L<Class::Accessor> both provide
 minimal object systems that take care of basic boilerplate for you.