X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=pod%2Fperlbot.pod;h=91723b70d787d6bf7f03976c516e6ed927ffb116;hb=4ad40acfc62db410aa4eb7654e17246f1fc97689;hp=e4952661b0b76e5910aa08c1c6e5f93a25e5ed20;hpb=697934ef381c2fbd2ff49c5e4b22e596a509b7a0;p=p5sagit%2Fp5-mst-13.2.git diff --git a/pod/perlbot.pod b/pod/perlbot.pod index e495266..91723b7 100644 --- a/pod/perlbot.pod +++ b/pod/perlbot.pod @@ -10,7 +10,8 @@ mechanics of object and class relationships. The reader is encouraged to consult relevant textbooks for discussion of Object Oriented definitions and methodology. This is not intended as a tutorial for object-oriented programming or as a comprehensive guide to Perl's object oriented features, -nor should it be construed as a style guide. +nor should it be construed as a style guide. If you're looking for tutorials, +be sure to read L, L, and L. The Perl motto still holds: There's more than one way to do it. @@ -104,14 +105,14 @@ variables. Named parameters are also demonstrated. package main; - $x = Foo->new( 'High' => 42, 'Low' => 11 ); - print "High=$x->{'High'}\n"; - print "Low=$x->{'Low'}\n"; - - $y = Bar->new( 'Left' => 78, 'Right' => 40 ); - print "Left=$y->[0]\n"; - print "Right=$y->[1]\n"; - + $a = Foo->new( 'High' => 42, 'Low' => 11 ); + print "High=$a->{'High'}\n"; + print "Low=$a->{'Low'}\n"; + + $b = Bar->new( 'Left' => 78, 'Right' => 40 ); + print "Left=$b->[0]\n"; + print "Right=$b->[1]\n"; + =head1 SCALAR INSTANCE VARIABLES An anonymous scalar can be used when only one instance variable is needed. @@ -127,8 +128,8 @@ An anonymous scalar can be used when only one instance variable is needed. package main; - $x = Foo->new( 42 ); - print "a=$$x\n"; + $a = Foo->new( 42 ); + print "a=$$a\n"; =head1 INSTANCE VARIABLE INHERITANCE @@ -159,9 +160,9 @@ object. package main; - $x = Foo->new; - print "buz = ", $x->{'buz'}, "\n"; - print "biz = ", $x->{'biz'}, "\n"; + $a = Foo->new; + print "buz = ", $a->{'buz'}, "\n"; + print "biz = ", $a->{'biz'}, "\n"; @@ -191,9 +192,9 @@ relationships between objects. package main; - $x = Foo->new; - print "buz = ", $x->{'Bar'}->{'buz'}, "\n"; - print "biz = ", $x->{'biz'}, "\n"; + $a = Foo->new; + print "buz = ", $a->{'Bar'}->{'buz'}, "\n"; + print "biz = ", $a->{'biz'}, "\n"; @@ -242,6 +243,9 @@ where that method is defined. $foo->goo; $foo->google; +Note that C refers to the superclasses of the current package +(C), not to the superclasses of C<$self>. + =head1 USING RELATIONSHIP WITH SDBM @@ -314,8 +318,8 @@ that it is impossible to override the BAZ() method. package main; - $x = FOO->new; - $x->bar; + $a = FOO->new; + $a->bar; Now we try to override the BAZ() method. We would like FOO::bar() to call GOOP::BAZ(), but this cannot happen because FOO::bar() explicitly calls @@ -351,8 +355,8 @@ FOO::private::BAZ(). package main; - $x = GOOP->new; - $x->bar; + $a = GOOP->new; + $a->bar; To create reusable code we must modify class FOO, flattening class FOO::private. The next example shows a reusable class FOO which allows the @@ -386,8 +390,8 @@ method GOOP::BAZ() to be used in place of FOO::BAZ(). package main; - $x = GOOP->new; - $x->bar; + $a = GOOP->new; + $a->bar; =head1 CLASS CONTEXT AND THE OBJECT @@ -444,10 +448,10 @@ method where that data is located. package main; - $x = Bar->new; - $y = Foo->new; - $x->enter; - $y->enter; + $a = Bar->new; + $b = Foo->new; + $a->enter; + $b->enter; =head1 INHERITING A CONSTRUCTOR @@ -476,8 +480,8 @@ object will be a BAR not a FOO, even though the constructor is in class FOO. package main; - $x = BAR->new; - $x->baz; + $a = BAR->new; + $a->baz; =head1 DELEGATION @@ -525,3 +529,7 @@ behavior by adding custom FETCH() and STORE() methods, if this is desired. tie %foo, "Mydbm", "adbm", O_RDWR|O_CREAT, 0640; $foo{'bar'} = 123; print "foo-bar = $foo{'bar'}\n"; + +=head1 SEE ALSO + +L, L, L.