in reply to Inheritance confusion

Please make it clear when you make changes to your posts (a SUPER suddenly popped up ;).

The fact is that the new class method in:

my $self = $class->SUPER::new(@_);
does not give back a DBIx::SQLEngine object, but a DBIx::SQLEngine::Driver::Mysql::V3_0 one as you can see from the debugger:
DB<3> x $sqldb 0 DBIx::SQLEngine::Driver::Mysql::V3_0=HASH(0x1a7c478) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
I suspect that the fetch_select method is actually present in this latter class, not in the frontend DBIx::SQLEngine, hence the problems. Are you sure that the DBIx::SQLEngine is intended for subclassing?

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

Don't fool yourself.

Replies are listed 'Best First'.
Re^2: Inheritance confusion
by srdst13 (Pilgrim) on Aug 08, 2006 at 17:12 UTC

    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

      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
      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.