In perl.git, the branch blead has been updated <http://perl5.git.perl.org/perl.git/commitdiff/a75f6a0b013c6142133284dab143f1ad0e581b10?hp=bb93890c7f6776cf9d28935e93153fe3c3cbb064>
- Log ----------------------------------------------------------------- commit a75f6a0b013c6142133284dab143f1ad0e581b10 Author: Dave Rolsky <[email protected]> Date: Tue Nov 1 14:34:03 2016 -0500 Added note about perlobj change to perldelta M pod/perldelta.pod commit 5e1bcc6bb797de68a23f5fdc0a53d38bcdd057b0 Author: Lukas Mai <[email protected]> Date: Tue Nov 1 14:25:21 2016 -0500 Add docs on calling methods using a fully qualified name like $mp3->File::save() M pod/perlobj.pod commit 3556f4bef612c7706067de56bf457739e80cf2e4 Author: Dave Rolsky <[email protected]> Date: Tue Nov 1 14:24:45 2016 -0500 Small formatting fix in perlobj M pod/perlobj.pod commit 10e32c8dba51985899a77b9d87327e60af56bd6f Author: Dave Rolsky <[email protected]> Date: Tue Nov 1 14:21:44 2016 -0500 Add a few more mentions of Moo to perlootut Also ran Porting/podtidy which reformatted a few lines. M pod/perlootut.pod ----------------------------------------------------------------------- Summary of changes: pod/perldelta.pod | 4 ++-- pod/perlobj.pod | 32 ++++++++++++++++++++++++++++++-- pod/perlootut.pod | 20 +++++++++++--------- 3 files changed, 43 insertions(+), 13 deletions(-) diff --git a/pod/perldelta.pod b/pod/perldelta.pod index 9bef257..d686561 100644 --- a/pod/perldelta.pod +++ b/pod/perldelta.pod @@ -157,13 +157,13 @@ XXX Changes which significantly change existing files in F<pod/> go here. However, any changes to F<pod/perldiag.pod> should go in the L</Diagnostics> section. -=head3 L<XXX> +=head3 L<perlobj> =over 4 =item * -XXX Description of the change here +Added a section on calling methods using their fully qualified names. =back diff --git a/pod/perlobj.pod b/pod/perlobj.pod index d16f800..483220a 100644 --- a/pod/perlobj.pod +++ b/pod/perlobj.pod @@ -489,8 +489,8 @@ As you can see, we've stored the path and file data in the object itself. Remember, under the hood, this object is still just a hash. Later, we'll write accessors to manipulate this data. -For our File::MP3 class, we can check to make sure that the path we're -given ends with ".mp3": +For our C<File::MP3> class, we can check to make sure that the path +we're given ends with ".mp3": package File::MP3; @@ -581,6 +581,34 @@ X<method> Perl supports several other ways to call methods besides the C<< $object->method() >> usage we've seen so far. +=head3 Method Names with a Fully Qualified Name + +Perl allows you to call methods using their fully qualified name (the +package and method name): + + my $mp3 = File::MP3->new( 'Regin.mp3', $data ); + $mp3->File::save(); + +When you a fully qualified method name like C<File::save>, the method +resolution search for the C<save> method starts in the C<File> class, +skipping any C<save> method the C<File::MP3> class may have defined. It +still searches the C<File> class's parents if necessary. + +While this feature is most commonly used to explicitly call methods +inherited from an ancestor class, there is no technical restriction +that enforces this: + + my $obj = Tree->new(); + $obj->Dog::bark(); + +This calls the C<bark> method from class C<Dog> on an object of class +C<Tree>, even if the two classes are completely unrelated. Use this +with great care. + +The C<SUPER> pseudo-class that was described earlier is I<not> the same +as calling a method with a fully-qualified name. See the earlier +L</Inheritance> section for details. + =head3 Method Names as Strings Perl lets you use a scalar variable containing a string as a method diff --git a/pod/perlootut.pod b/pod/perlootut.pod index 4d07f29..b340dc6 100644 --- a/pod/perlootut.pod +++ b/pod/perlootut.pod @@ -232,8 +232,8 @@ from C<File>. An C<File::MP3> B<is-a> I<more specific> type of C<File>. All mp3 files are files, but not all files are mp3 files. We often refer to inheritance relationships as B<parent-child> or -C<superclass>/C<subclass> relationships. Sometimes we say that the child -has an B<is-a> relationship with its parent class. +C<superclass>/C<subclass> relationships. Sometimes we say that the +child has an B<is-a> relationship with its parent class. C<File> is a B<superclass> of C<File::MP3>, and C<File::MP3> is a B<subclass> of C<File>. @@ -650,8 +650,8 @@ constructor for your class. Finally, we have L<Class::Tiny>. This module truly lives up to its name. It has an incredibly minimal API and absolutely no dependencies -on any recent Perl. Still, we think it's a lot easier to use than writing -your own OO code from scratch. +on any recent Perl. Still, we think it's a lot easier to use than +writing your own OO code from scratch. Here's our C<File> class once more: @@ -715,9 +715,9 @@ to worry about details. =item * L<Role::Tiny> -Use C<Role::Tiny> with C<Class::Accessor> or C<Class::Tiny> if you -find yourself considering multiple inheritance. If you go with -C<Moose>, it comes with its own role implementation. +Use C<Role::Tiny> with C<Class::Accessor> or C<Class::Tiny> if you find +yourself considering multiple inheritance. If you go with C<Moose>, it +comes with its own role implementation. =back @@ -743,9 +743,11 @@ For small systems, L<Class::Tiny> and L<Class::Accessor> both provide minimal object systems that take care of basic boilerplate for you. For bigger projects, L<Moose> provides a rich set of features that will -let you focus on implementing your business logic. +let you focus on implementing your business logic. L<Moo> provides a +nice alternative to L<Moose> when you want a lot of features but need +faster compile time or to avoid XS. -We encourage you to play with and evaluate L<Moose>, +We encourage you to play with and evaluate L<Moose>, L<Moo>, L<Class::Accessor>, and L<Class::Tiny> to see which OO system is right for you. -- Perl5 Master Repository
