Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

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


In reply to A couple questions about object oriented Perl programming: inheritance and error handling by ted.byers

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others avoiding work at the Monastery: (8)
    As of 2014-04-19 23:01 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      April first is:







      Results (485 votes), past polls