Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Public/Private Data/Funcion in Perl OO?

Reply
Thread Tools

Public/Private Data/Funcion in Perl OO?

 
 
Davy
Guest
Posts: n/a
 
      08-07-2006
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??

Thanks!
Davy

 
Reply With Quote
 
 
 
 
anno4000@radom.zrz.tu-berlin.de
Guest
Posts: n/a
 
      08-07-2006
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
 
Reply With Quote
 
 
 
 
AC
Guest
Posts: n/a
 
      08-07-2006

<> wrote in message
news:...
> 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


You should check out Damian Conway'a "Perl Best Practices". It covers these
issues exactly. You can use "inside out" objects to hide data and you can
use anonymous code refs to achieve private methods. Its been a while since I
read the book, so I'm not sure about how to get protected behavior.

Allan


 
Reply With Quote
 
anno4000@radom.zrz.tu-berlin.de
Guest
Posts: n/a
 
      08-07-2006
AC <clarke@n_o_s_p_a_m_hyperformix.com> wrote in comp.lang.perl.misc:
>
> <> wrote in message
> news:...
> > 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

>
> You should check out Damian Conway'a "Perl Best Practices". It covers these
> issues exactly. You can use "inside out" objects to hide data


Right. There is no possible access to the data of an inside-out object,
except through the accessors you provide.

> and you can
> use anonymous code refs to achieve private methods. Its been a while since I
> read the book, so I'm not sure about how to get protected behavior.


I don't have the book to hand (don't books have a way of being where you
aren't?), but I don't see how anonymous code refs could ever participate
in inheritance. For inheritance, methods *must* be named and can't be
strictly private.

Anno
 
Reply With Quote
 
Uri Guttman
Guest
Posts: n/a
 
      08-07-2006
>>>>> "D" == Davy <> writes:

D> I am a C++ programmer and new to Perl.

we know you are new to perl already so stop saying it.

and you should really read a good book on perl before you continue your
education via usenet. it will be much more efficient for both you and
us. learn.perl.org has a good free book and the perl docs are very good
too. read a bunch first before you continue posting again and you will
feel much better.

uri

--
Uri Guttman ------ -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
 
Reply With Quote
 
Jimi-Carlo Bukowski-Wills
Guest
Posts: n/a
 
      08-08-2006
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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
FAQ 2.17 What is perl.com? Perl Mongers? pm.org? perl.org? cpan.org? PerlFAQ Server Perl Misc 0 04-04-2011 10:00 PM
FAQ 1.4 What are Perl 4, Perl 5, or Perl 6? PerlFAQ Server Perl Misc 0 02-27-2011 11:00 PM
FAQ 2.17 What is perl.com? Perl Mongers? pm.org? perl.org? cpan.org? PerlFAQ Server Perl Misc 0 02-03-2011 11:00 AM
FAQ 1.4 What are Perl 4, Perl 5, or Perl 6? PerlFAQ Server Perl Misc 0 01-23-2011 05:00 AM
Perl Help - Windows Perl script accessing a Unix perl Script dpackwood Perl 3 09-30-2003 02:56 AM



Advertisments