Brian McCauley said:
Don't use inheritance - use AUTOLOAD.
sub AUTOLOAD : lvalue {
my ($method) = do { our($AUTOLOAD) =~ /(\w+$)/ };
# added stuff
$method = "ParentClass::$method";
shift->$method(@_);
}
Note lvalued AUTOLOAD doesn't work (actually crashes compiler) in 5.6
Ok - I had to do some O'Reilly searching on this one. I think I understand
how this works. However during my reading - I saw this in Programming Perl:
"After Perl has vainly looked through an object's class package and the
packages of its base classes to find a method, it also checks for an
AUTOLOAD routine in each package before concluding that the method can't be
found."
So now - I'm not sure if this will work because there are other constraints.
i.e. I need to "use The:
arentModule" within my module - so this means that
the methods will be found and AUTOLOAD will not be called. Is this a correct
understanding?
I will describe exactly what I am trying to do.
I am trying to create a composite Tk widget which adds line numbers to a
Tk::Text widget (or for that matter any other widget which uses Tk::Text as
a base). In order to catch all user and programmed events for changes to the
contents - I wish to call a subroutine which updates the line numbers
whenever *any* method is called which is related to Tk::Text or Tk::WhatEver
(where WhatEver is derived from Tk::Text)
Here are some constraints:
1. I must allow the name of any Tk::Text derived module to be passed.
2. This module must be "use" d within my package..
Will AUTOLOAD still work in this case?
I have already released a beta version of this called Tk::LineNumberText to
CPAN - but it actually overwrites (ugh!)the Text-based methods - something
which I do not want to do. Hackery - shame..
Jack