in reply to How can I inherit from Bit::Vector?

Greetings,

I am posting what follows by toma's request (very nearly yanked from somewhere in the panther bbok, so I cannot really claim authorship :) ).

package My::Tmain; sub new { #somewhere... $self_>{_TMAIN_}=Win32::OLE->new('mynifty.application') or barf('badly'); #... bless $pkg $self; } #override something sub foo { my $self=shift; my $res = $self->{_TMAIN_}->foo(@_); munge($res); } #elsewhere sub AUTOLOAD { my($self,@args)=(@_); my($cmd); ($cmd=$AUTOLOAD)=~s/.*:://; return if $cmd eq 'DESTROY'; # should not even be called { #this may be bititing toma... no strict 'refs'; # this does the delegation hokey dokey $self->{_TMAIN_}->$cmd(@args); } } #in another file use My::Tmain; my $t= My::Tmain->new(); $t->foo(); # calls the overridden method $t->bar(); # autoloaded
Note that no strict refs is required to make the ->$cmd( ) bit work. I see nothing that should stop this from working with Bit::Vector... but then again, I would not have anticipated the impossibility to inherit. Manual overriding is obviously possible but much more tedious and error prone than this


Cheers,
alf


You can't have everything: where would you put it?