Hi,
I have a book called "Writing Perl Modules for CPAN" and it's my favourite
book ever! See if you can get a copy. In it is detailed a way to make
something private and enforcing it by using an anonymous sub.
This book will probably introduce you to Perl from the right direction,
since it makes sense for you to find out what Perl does and doesn't do in
comparison to C++ as soon as possible.
Anyway, the solution is you have your new sub return an anonymous sub that
then sets up the internal data using the my keyword... spot the problem
here??? Yes! Suddenly EVERYTHING is private (well, all of the variables
anyway) so that you need accessors/mutators for everything... which are
difficult to roll automatically in this case.
I guess the short answer is: it's possible, but don't bother!
J
Reference:
Sam Tregar, Writing Perl Modules for CPAN, Apress/Springer NY 2002
(Try
www.apress.com or
www.springer-ny.com)
On Mon, 07 Aug 2006 10:50:34 +0000, anno4000 wrote:
> Davy <> wrote in comp.lang.perl.misc:
>> Hi all,
>>
>> I am a C++ programmer and new to Perl.
>> Is there some equal idea like Public/Private Data/Funcion in Perl OO?
>> I found the tutorial provided by Perldoc show all the Data is public??
>
> Right about methods (and subs in general). There is only the convention
> to let the names of private methods begin with an underscore (_private).
> That doesn't stop anyone from using them, but at least they'll know they
> are doing something wrong.
>
> Data stored in lexical variables are inaccessible from outside their scope
> so they are truly private. This is not true for package variables.
>
> Anno