On Sat, 03 Mar 2007 22:23:04 -0500, Jeff Pang wrote:
> Does Perl's OO have "private method" like Python and other OO languages?
> When we say "sub foo { }" in a package 'bar',Perl will insert the "foo"
> into this package's symbol table,so we can access foo() from anywhere
> out of the package bar,via the form of "bar::foo()". So I don't think
> Perl has its private method.Or we can make a private method by declaring
> an anonymous subroutine of "sub { }".Am I right?

Class::Std allows one to attach a :PRIVATE attribute to any
method, which makes it truly private (there is also a :RESTRICTED
attribute for this class and subclasses only).  Behind the scenes it
overrides the method with one that checks the caller and calls the
original code if permitted, which is now only available via reference.

Of course, you can always put your caller in the same package as the
private method... but you asked about privacy to the package, not the file.

-- 
Peter Scott
http://www.perlmedic.com/
http://www.perldebugged.com/


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to