http://www.perlmonks.org?node_id=1029204

ted.byers has asked for the wisdom of the Perl Monks concerning the following question:

The first is probably the easiest. I am quite used to object oriented proramming in C++ (one of my favourite languages) and Java; and I have seen a number of different treatments of object oriented programming in perl, but have not seen anything yet about accessing data in a base class from the derived class). Nor have I seen anything especially useful in terms of multiple inheritance (something I keep to an absolute minimum in the other languages I use as far as is practicable). Can anyone point me to a thorough treatment of access to data in base classes, access control (what I have in mind is the Perl equivalent, if there is one, to private, protected and public access), and the complexities of multiple inheritance?

I am using my own access package to manage a user's authentication and authorization, and for the most part, this works beautifully. However, this is a web application, and I use the following for session management:

sub new { my $class = shift; my $query = shift; my $base = $query->url(-base => 1); my $cgi = $base; $cgi .= "/cgi-bin/"; my $self = {}; $self->{'base_url'} = $base; $self->{'rel_url'} = $query->url(-relative => 1); $self->{'cgi_url'} = $cgi; croak "Function new takes a an instance of class CGI as an argument +- dying a nasty death!\n" unless (defined $query); croak "Function new takes a an instance of class CGI as an argument +- dying a nasty death!\n" unless $query->isa('CGI'); my $session = shift; if ($session->is_expired()) { my $login_script = $base . "/login.html"; print $query->redirect($login_script); return; # exit(0); }

The usual call sequence is one creates a CGI object, and from that creates a CGI::Session object. Both are passed to function new, as the above code shows. After an object has been created, any number of other functions may be invoked before the cgi script exits. What happens is that when the user's session times out, he gets an error to the effect that we can't use the string "ERROR" as a HASH ref, while "strict refs" is use. I guess there are a couple things pertaining to this. The first involves what is the best practice for handling errors deep in the bowels of a package or object, about which the calling code ought to be blissfully ignorant. Is there, a way to detect an error condition within the classes member functions before doing what they are designed to do (so they can do nothing, except possibly log the error, if there is an error condition)? Or, is there something within Perl that serves the same requirements that C++ exceptions serve in C++. And the second is whether or not my redirection code shown above ought to be using exit in case of redirection instead of return, after the redirection header has been written.

Thanks

Ted