in reply to Re: Inheritance confusion
in thread Inheritance confusion

I don't know whether or not it is meant to be subclassed--there is no mention that it is, so quite possibly not. If it returns a blessed hash, shouldn't I be able to bless that into my own class? Or is there more to it than that? I looked through perltoot again; there is plenty of discussion of making your own classes, but it doesn't answer the question of exactly what needs to happen to be heritable.

Finally, thanks for the $class->SUPER::new() correction. In my frustration, I had changed the code to the unintelligible form that I originally posted.

Sean

Replies are listed 'Best First'.
Re^3: Inheritance confusion
by eric256 (Parson) on Aug 08, 2006 at 17:22 UTC

    Hey. It sounds like it is a factory. As such it returns a different object type, not its own. You should be able to rebless this, but you'll have to change your ISA to refelct the actual parent instead of the factory. Maybe you can dynamicaly find out the object you recieves type, then add that to the ISA and rebless yours? This would be a problem if you use your factory to create more than one type of object. I don't think perl supplies a way for each object to store its own class info like some sort of anonymous class....i bet perl6 does though ;)

    All information in the post is suspect to error as i'm just guessing here


    ___________
    Eric Hodges
Re^3: Inheritance confusion
by polettix (Vicar) on Aug 08, 2006 at 23:56 UTC
    I'm really too lazy to dwelve into the inheritance tree of DBIx::SQLEngine, but the bottom line is probably that you're inheriting from one class but the $self you get belongs to a different one. As eric256 suggests you could cope with some run-time modification of @ISA, in order to include the real class of $self, e.g.:
    sub new { my $class = shift; my $self = DBIx::SQLEngine->new(@_); no strict 'refs'; push @{$class . '::ISA'}, ref $self; return bless $self, $class; }
    Before you decide to take this path be sure to read this thread!

    Flavio
    perl -ple'$_=reverse' <<<ti.xittelop@oivalf

    Don't fool yourself.