Explicitly calling a parent classes method from a child class

John Harrison ash.gti at gmail.com
Mon Aug 10 15:38:59 UTC 2009


There doesn't currently seem to be an tests or anything in the spec  
about doing this. This seems like it would be a useful feature for  
classes to be able to do. It would be useful for any case where you  
wanted to extend a function rather than completely replace it.  
Currently, (as far as I can tell) in parrot if you override a method  
in a subclass you can no longer call methods from the parent. It would  
be useful to be able to explicitly call a method from a parent. This  
would also be useful in a the same context with roles.

In perl 6 it would be something along the lines of: (here is this code  
in gist form, http://gist.github.com/165247 )

class A {
	method foo { say 'A::test'; }
}

class B is A {
	method foo {
		self.A::foo;
		say 'but also B::foo';
	}
}

my B $b .= new;
$b.foo;

I currently have not been able to find an example of how this would  
work in parrot itself. When you try to do this in perl you get an  
error message saying "Method 'A::foo' not found for invocant of class  
'B'" which is a parrot level error message. Thats why I am asking in  
here, not in the perl 6 development mailing list.

Thanks,
John


More information about the parrot-dev mailing list