but not finding the CGI object in itself ( because it's superclass data )
No! The data is in the object, not the superclass. There's no reason you can't still get it from $self->{_cgi}, because the HandlerMethods object is still a Handler object too -- otherwise you wouldn't have made the former a subclass of the latter.

Just change this:

return ( $caller eq 'Handler' ? $self->{_cgi} : $self->SUPER::->{_ +cgi} );
.. to this:
return $self->{_cgi};
.. and the code should do what you want. Your new constructor as you have it is fine, and you shouldn't need to change it..

Never put special logic (like the caller business here) in the superclass: a superclass shouldn't know about its subclasses. I have a feeling you are really overthinking the complexity of inheritance. It's really a lot simpler than you have attempted here -- it Just Works. Write the method to work on your Handler objects, and it will Just Work for the subclasses too.

You should really reread Perl's OO documentation (perlbot, perltoot, perlboot, perlobj, to name a few), specifically about inheritance and SUPER.

SUPER:: comes into play when the subclass wants to refine the behavior of an existing method. You tried to use SUPER:: from the superclass (and with a hash dereference, not a method), which is definitely not what you want here.

Here's an example of a correct use of SUPER. Say you want HandlerMethods to refine the behavior of cgi method of Handler:

package HandlerMethods; sub cgi { my $self = shift; ## first, get whatever the superclass would return my $cgi_obj = $self->SUPER::cgi; ## then we can slightly refine.. $cgi_obj->param('HandlerMethods', 1); return $cgi_obj; }
Notice how HandlerMethods objects still have a cgi method that behaves just as a Handler object does, but it just adds a little something.

I hope I cleared a few things up!

blokhead


In reply to Re: accessing superclass data by blokhead
in thread accessing superclass data by geektron

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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.