in reply to Trying to re-use code at different levels of an inherited object.

chromatic nailed it. Your problem is that though the function that SUPER::do_something is being called in is called from a function in package Bar, the code was compiled in package Foo and so tries to access the SUPER of the method from package Foo. (Similarly if you call a function from a closure, your package and line number as seen from caller is the package and line number where the code was when you created the closure.)

Therefore to do what you are trying you need to actually compile it in the package that you want. So you can still do what you want, but you need to use a string eval to get it to work right.

For an example of the technique, complete with debugging hooks so that errors are reported from something more meaningful than just some eval, take a look at how I implemented AbstractClass. (Look at the end of perlsyn for an explanation of the #line business.)

  • Comment on Re (tilly) 1: Trying to re-use code at different levels of an inherited object.