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:
.. to this:return ( $caller eq 'Handler' ? $self->{_cgi} : $self->SUPER::->{_ +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..return $self->{_cgi};
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:
Notice how HandlerMethods objects still have a cgi method that behaves just as a Handler object does, but it just adds a little something.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; }
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |