Thread

Posted on Fri Nov 9 16:33:28 2007 by jpeterman
Polymorphism broken for foreign class inheritance
Hi,
I'm trying to sub class Data::Table and override the colIndex function to ignore case. I'd like to use an InsideOut object, but it seems to get chopped when invoking parent methods. Here is a script that shows the problem. MyChild::inner_call never gets invoked. Am I doing something wrong?
Thanks, J
#!/usr/bin/env perl use warnings; use strict; use Carp; #use Smart::Comments; # old style hash based perl object package MyParent; require Exporter; require AutoLoader; use vars qw(@ISA); @ISA = qw(Exporter AutoLoader); { sub new { my ($pkg, $d) = @_; my $class = ref($pkg) || $pkg; my $self = {data => $d}; return bless $self, $class; } sub inner_call { my ($self) = @_; #print "MyParent::inner_call\n"; return $self->{data}; } sub parent_call { my ($self) = @_; #print "MyParent::parent_call\n"; ### $self: "$self" return $self->inner_call(); } } # new style InsideOut object package MyChild; use Object::InsideOut qw(MyParent); { sub init :Init { my ($self, $args) = @_; my $parent = MyParent->new($args->{base}); $self->inherit($parent); } sub inner_call { my ($self) = @_; #print "MyChild::inner_call\n"; return $self->heritage('MyParent')->inner_call() . " MyChild"; } sub child_call { my ($self) = @_; #print "MyChild::child_call\n"; ### $self: "$self" return $self->parent_call(); } } package main; my $obj = MyChild->new( base => "MyParent" ); print " child: " . $obj->child_call() . "\n"; print "parent: " . $obj->parent_call() . "\n"; exit(0);
Direct Responses: 6427 | Write a response
Posted on Fri Nov 9 17:49:55 2007 by jdhedden in response to 6426
Re: Polymorphism broken for foreign class inheritance
The problem is that OIO's AUTOLOAD subroutine handles the dispatching of foreign method calls using the internally held inherited object. As such, parent_call receives the internal MyParent object which, of course, doesn't know anything about the MyChild class.

I see what it is you're trying to do, but I can't think of a way to do it given OIO's foreign inheritance mechanism.

One suggestion is to try re-engineering the methods being called.

Otherwise, you might see if Class::InsideOut can do what you want.

Thanks for trying to use OIO. Sorry I couldn't be of more help.
Write a response