[perl #51964] Typo on regular expression at perlopentut manual page.
[p5sagit/p5-mst-13.2.git] / pod / perlboot.pod
index bab3656..6e3f5ac 100644 (file)
@@ -7,7 +7,7 @@ perlboot - Beginner's Object-Oriented Tutorial
 If you're not familiar with objects from other languages, some of the
 other Perl object documentation may be a little daunting, such as
 L<perlobj>, a basic reference in using objects, and L<perltoot>, which
-introduces readers to the pecularities of Perl's object system in a
+introduces readers to the peculiarities of Perl's object system in a
 tutorial way.
 
 So, let's take a different approach, presuming no prior object
@@ -26,7 +26,7 @@ Let's let the animals talk for a moment:
       print "a Horse goes neigh!\n";
     }
     sub Sheep::speak {
-      print "a Sheep goes baaaah!\n"
+      print "a Sheep goes baaaah!\n";
     }
 
     Cow::speak;
@@ -106,7 +106,7 @@ example:
       print "a Horse goes neigh!\n";
     }
     sub Sheep::speak {
-      print "a Sheep goes baaaah!\n"
+      print "a Sheep goes baaaah!\n";
     }
 
     @pasture = qw(Cow Cow Horse Sheep Sheep);
@@ -139,8 +139,8 @@ attempts to invoke subroutine C<Class::method> as:
 
 (If the subroutine can't be found, "inheritance" kicks in, but we'll
 get to that later.)  This means that we get the class name as the
-first parameter.  So we can rewrite the C<Sheep> speaking subroutine
-as:
+first parameter (the only parameter, if no arguments are given).  So
+we can rewrite the C<Sheep> speaking subroutine as:
 
     sub Sheep::speak {
       my $class = shift;
@@ -172,7 +172,7 @@ This method provides the constant text for the sound itself.
       sub sound { "moooo" }
       sub speak {
        my $class = shift;
-       print "a $class goes ", $class->sound, "!\n"
+       print "a $class goes ", $class->sound, "!\n";
       }
     }
 
@@ -184,7 +184,7 @@ returns C<moooo>.  But how different would this be for the C<Horse>?
       sub sound { "neigh" }
       sub speak {
        my $class = shift;
-       print "a $class goes ", $class->sound, "!\n"
+       print "a $class goes ", $class->sound, "!\n";
       }
     }
 
@@ -200,7 +200,7 @@ definition for C<speak>:
     { package Animal;
       sub speak {
        my $class = shift;
-       print "a $class goes ", $class->sound, "!\n"
+       print "a $class goes ", $class->sound, "!\n";
       }
     }
 
@@ -238,21 +238,22 @@ not a simple single value, because on rare occasions, it makes sense
 to have more than one parent class searched for the missing methods.
 
 If C<Animal> also had an C<@ISA>, then we'd check there too.  The
-search is recursive, depth-first, left-to-right in each C<@ISA>.
-Typically, each C<@ISA> has only one element (multiple elements means
-multiple inheritance and multiple headaches), so we get a nice tree of
-inheritance.
+search is recursive, depth-first, left-to-right in each C<@ISA> by
+default (see L<mro> for alternatives).  Typically, each C<@ISA> has
+only one element (multiple elements means multiple inheritance and
+multiple headaches), so we get a nice tree of inheritance.
 
 When we turn on C<use strict>, we'll get complaints on C<@ISA>, since
 it's not a variable containing an explicit package name, nor is it a
-lexical ("my") variable.  We can't make it a lexical variable though,
+lexical ("my") variable.  We can't make it a lexical variable though
+(it has to belong to the package to be found by the inheritance mechanism),
 so there's a couple of straightforward ways to handle that.
 
 The easiest is to just spell the package name out:
 
     @Cow::ISA = qw(Animal);
 
-Or allow it as an implictly named package variable:
+Or allow it as an implicitly named package variable:
 
     package Cow;
     use vars qw(@ISA);
@@ -335,7 +336,7 @@ subroutine.
 
 Also note that the C<Animal> classname is now hardwired into the
 subroutine selection.  This is a mess if someone maintains the code,
-changing C<@ISA> for <Mouse> and didn't notice C<Animal> there in
+changing C<@ISA> for C<Mouse> and didn't notice C<Animal> there in
 C<speak>.  So, this is probably not the right way to go.
 
 =head2 Starting the search from a different place
@@ -381,7 +382,8 @@ listed in C<@ISA>) automatically:
     }
 
 So, C<SUPER::speak> means look in the current package's C<@ISA> for
-C<speak>, invoking the first one found.
+C<speak>, invoking the first one found. Note that it does I<not> look in
+the C<@ISA> of C<$class>.
 
 =head2 Where we're at so far...
 
@@ -421,7 +423,7 @@ and the C<Horse> class:
   { package Animal;
     sub speak {
       my $class = shift;
-      print "a $class goes ", $class->sound, "!\n"
+      print "a $class goes ", $class->sound, "!\n";
     }
   }
   { package Horse;
@@ -490,7 +492,7 @@ If Horse::sound had not been found, we'd be wandering up the
 C<@Horse::ISA> list to try to find the method in one of the
 superclasses, just as for a class method.  The only difference between
 a class method and an instance method is whether the first parameter
-is a instance (a blessed reference) or a class name (a string).
+is an instance (a blessed reference) or a class name (a string).
 
 =head2 Accessing the instance data
 
@@ -552,6 +554,17 @@ C<Horse::named> are C<Horse> and C<Mr. Ed>.  The C<bless> operator
 not only blesses C<$name>, it also returns the reference to C<$name>,
 so that's fine as a return value.  And that's how to build a horse.
 
+We've called the constructor C<named> here, so that it quickly denotes
+the constructor's argument as the name for this particular C<Horse>.
+You can use different constructors with different names for different
+ways of "giving birth" to the object (like maybe recording its
+pedigree or date of birth).  However, you'll find that most people
+coming to Perl from more limited languages use a single constructor
+named C<new>, with various ways of interpreting the arguments to
+C<new>.  Either style is fine, as long as you document your particular
+way of giving birth to an object.  (And you I<were> going to do that,
+right?)
+
 =head2 Inheriting the constructor
 
 But was there anything specific to C<Horse> in that method?  No.  Therefore,
@@ -561,7 +574,7 @@ C<Animal>, so let's put it there:
   { package Animal;
     sub speak {
       my $class = shift;
-      print "a $class goes ", $class->sound, "!\n"
+      print "a $class goes ", $class->sound, "!\n";
     }
     sub name {
       my $self = shift;
@@ -597,7 +610,7 @@ shows up as we saw it just now.
 All we need is for a method to detect if it is being called on a class
 or called on an instance.  The most straightforward way is with the
 C<ref> operator.  This returns a string (the classname) when used on a
-blessed reference, and C<undef> when used on a string (like a
+blessed reference, and an empty string when used on a string (like a
 classname).  Let's modify the C<name> method first to notice the change:
 
   sub name {
@@ -778,9 +791,13 @@ Hopefully, this gets you started, though.
 
 For more information, see L<perlobj> (for all the gritty details about
 Perl objects, now that you've seen the basics), L<perltoot> (the
-tutorial for those who already know objects), L<perlbot> (for some
-more tricks), and books such as Damian Conway's excellent I<Object
-Oriented Perl>.
+tutorial for those who already know objects), L<perltooc> (dealing
+with class data), L<perlbot> (for some more tricks), and books such as
+Damian Conway's excellent I<Object Oriented Perl>.
+
+Some modules which might prove interesting are Class::Accessor,
+Class::Class, Class::Contract, Class::Data::Inheritable,
+Class::MethodMaker and Tie::SecureHash
 
 =head1 COPYRIGHT