On May 20, 2004, at 8:32 AM, Graeme McLaren wrote:
Hi, I'm starting to look at OO in PERL, I've written a working class but I don't know how to implement private and public variables and accessor functions, any idea how to do that?
Perl takes a very lax view on the whole security issue of objects.
From that point of view, the first step is to ask yourself if you really NEED public methods/data? As you say, you have a working class now. What's wrong with it?
That view aside, you do have some options. They vary in levels of paranoia and effectiveness. Here's an example of a simple private method:
my $private_method = sub { ... };
# and later, a call...
$self->$private_method( ... );
As far as data goes, convention is that private Perl instance data starts with an _. There are no rules in place to enforce this, but you could certainly code some, if you really must go that far...
Hope that helps.
James
P.S. Move your package line up, just under the shebang line.
P.P.S. Do you know that all objects are using the same query? This could be a feature or a bug, but worth mentioning.
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>