in reply to Private method variations
If you want to avoid namespace clashes, you can just avoid the method lookup entirely and pass the object as the first parameter to the private method (this happens anyway, we just aren't faking it). As a bonus, the subroutine lookup time is reduced:
my $private1 = sub { print "Private1\n" }; sub _private2 { print "Private2\n" } sub public_method { my $self = shift; $private1->($self); _private2($self); }
Calling like this shouldn't be done for public and protected methods because it breaks subclassing, but private methods aren't supposed to be subclassed anyway.
----
: () { :|:& };:
Note: All code is untested, unless otherwise stated
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Private method variations
by adrianh (Chancellor) on Mar 01, 2004 at 14:40 UTC | |
by TimToady (Parson) on Mar 01, 2004 at 17:46 UTC | |
by adrianh (Chancellor) on Mar 01, 2004 at 22:11 UTC | |
by TimToady (Parson) on Mar 02, 2004 at 00:57 UTC | |
by adrianh (Chancellor) on Mar 02, 2004 at 01:40 UTC | |
| |
by duff (Parson) on Mar 01, 2004 at 20:58 UTC | |
by TimToady (Parson) on Mar 02, 2004 at 00:46 UTC |
In Section
Meditations