Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: How can I inherit from Bit::Vector?

by alien_life_form (Pilgrim)
on Nov 05, 2001 at 21:02 UTC ( [id://123351]=note: print w/replies, xml ) Need Help??


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?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://123351]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2024-03-28 20:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found