[tpm] private method call nuances

Uri Guttman uri at stemsystems.com
Mon Jul 20 18:34:45 PDT 2009

>>>>> "AB" == Alex Beamish <talexb at gmail.com> writes:

  AB> On Mon, Jul 20, 2009 at 7:57 PM, Madison Kelly<linux at alteeve.com> wrote:
  >> Hi all,
  >>  I was wondering what, if anything, would be different between calling a
  >> module's (private) method in these two ways:
  >> $self->_count_module();
  >> - vs -
  >> &_count_module($self);
  >>  Of course, '$self' is a (hash) reference 'bless'ed into the current module.
  >> Functionally I don't see a difference (yet).

  AB> Functionally, I don't see a difference either, but I have to admit I
  AB> squirm whenever I see & in front of a function/method call.

there is a major difference between those. massive in fact.

  AB> Unless you're calling a reference to a sub, it's unnecessary (and
  AB> possibly mis-leading, because @_ is used as parameters if a function
  AB> is called with & and no parameters).

that is one very important issue. calling subs with & is bad in general.

  AB> Second, calling a method by passing $self in as the first parameter is
  AB> correct, but not OO-Perlish. The method _count_module is a method
  AB> (albeit a private one), and so should be called in an OO way.

actually it is incorrect since it bypasses any inheritance. even private
methods can inherit from parent classes. if you want to use a
local/private sub then you can pass parts of the object as you would in
any other call. you can even pass the object as OP did but it is just
bad coding to pass the object as the first arg.


Uri Guttman  ------  uri at stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Code Review , Architecture, Development, Training, Support ------
--------- Free Perl Training --- http://perlhunter.com/college.html ---------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------

More information about the toronto-pm mailing list