Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Structure of a custom class (using Apache::Session)

by JediWizard (Deacon)
on Jun 15, 2005 at 18:42 UTC ( [id://467013]=note: print w/replies, xml ) Need Help??


in reply to Structure of a custom class (using Apache::Session)

Should I be taking steps to protect my session data such as a closure? From my script I am able to do the following: my $id = $session_obj->{session}->{_session_id} – this defeats the point of OOP!

In Perl5 encapsulation (by default) is semantic. Polite client code should not touch any key of an object which begins with _. If you want strictly enforced encapsulation, Perl 5 may not be for you. There are ways to create well encapsulated objects in Perl 5, but the language doesn't do it for you. Consider:

package Encapsulated; my(%objects) = (); sub new { my $proto = shift; $proto = ref($proto) || $proto; my $junk; my $me = bless(\$junk, $proto); $objects{$me}{property} = 'something'; return $me; }

Notice that you now have a way to store properties of an object in such a way that makes them inaccessable to the client code? I think Damian may even cover that technique in his book (he does in his class "Intermediate OO Perl")


They say that time changes things, but you actually have to change them yourself.

—Andy Warhol

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://467013]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-03-29 05:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found