From: Michael Witten Date: Tue, 7 Apr 2009 19:59:29 +0000 (-0500) Subject: Docs: Minor modifications to discussion of constructor X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=64261f91d325cb53a52f189ce3dce7a4ef3c99ec;p=p5sagit%2Fp5-mst-13.2.git Docs: Minor modifications to discussion of constructor Signed-off-by: Michael Witten --- diff --git a/pod/perlboot.pod b/pod/perlboot.pod index 2426062..7d39843 100644 --- a/pod/perlboot.pod +++ b/pod/perlboot.pod @@ -561,8 +561,8 @@ Of course, if we constructed all of our horses by hand, we'd most likely make mistakes from time to time. We're also violating one of the properties of object-oriented programming, in that the "inside guts" of a Horse are visible. That's good if you're a veterinarian, -but not if you just like to own horses. So, let's let the Horse class -build a new horse: +but not if you just like to own horses. So, let's have the Horse +class handle the details inside a class method: { package Horse; @ISA = qw(Animal); @@ -578,14 +578,15 @@ build a new horse: } } -Now with the new C method, we can build a horse: +Now with the new C method, we can build a horse as follows: my $horse = Horse->named("Mr. Ed"); Notice we're back to a class method, so the two arguments to C are C and C. The C 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. +not only blesses C<$name>, it also returns that reference. + +This C method is called a "constructor". We've called the constructor C here, so that it quickly denotes the constructor's argument as the name for this particular C.