in reply to Private Class Methods
Method calls bypass Exporter, so no, this won't work.
There are several ways to do "private" methods.
- The standard way is to not bother enforcing private-ness. Just pre-pend an underscore (_) to your method names and let the user consciously make the choice to violate encapsulation.
- You can put a
That's known as a gatekeeper. I haven't seen that a lot. That kind of private allows inheritance to work. The other way, requiring that you must be of that class and that class alone would be to do something like ref $self eq __PACKAGE__, more akin to C++'s private.sub _my_private_method { my $self = shift; die "Private method, jerk!" unless UNIVERSAL::isa($self, __PACKAGE__); # ... Continue on here as normal } - This applies more to data, but you can change your reference from a hashref to a coderef, effectively making all your object instances closures. This would make all your data private. You could extend it to methods, I suppose. I wouldn't reccomend it because it's extremely non-standard and would be very hard to maintain. There's also a minor speed hit, but it's not that major.
------
We are the carpenters and bricklayers of the Information Age.
Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Private Class Methods
by perrin (Chancellor) on Apr 05, 2002 at 21:43 UTC | |
Re: Re: Private Class Methods
by RMGir (Prior) on Apr 06, 2002 at 14:27 UTC |
In Section
Meditations