8.9 What to Do with _


8.9 What to Do with @_

In that last example, had there been any additional parameters to the speak routine (like how many times, or in what pitch for singing , for example), the parameters would be ignored by the Mouse::speak routine. If you want them to be passed uninterpreted to the parent class, you can add it as a parameter:

 $class->SUPER::speak(@_); 

This invokes the speak routine of the parent class, including all the parameters that you've not yet shifted off of your parameter list.

Which one is correct? It depends. If you are writing a class that simply adds to some of the parent class behavior, it's best to simply pass along arguments you haven't dealt with. However, if you want precise control over the parent class behavior, you should determine the argument list explicitly, and pass it.



Learning Perl Objects, References & Modules
Learning Perl Objects, References, and Modules
ISBN: 0596004788
EAN: 2147483647
Year: 2003
Pages: 199

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net