Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: @ISA, Inheritance, and Class Methods

by Adam (Vicar)
on Mar 13, 2001 at 10:41 UTC ( [id://64076]=note: print w/replies, xml ) Need Help??


in reply to @ISA, Inheritance, and Class Methods

I must admit that I too have fallen in the @ISA trap. But I wanted to look at your solution to extending an existing module. Not that long ago I was looking at using an OO module (I honestly don't remember which one), but this module didn't have a destructor. Instead, you were required to call some kind of clean up method, lets call it Class::Finish(). Well, I'm not a big fan of making the programmer call something that Perl will happily do for you (if you call the method DESTROY) and so I thought about how to extend the class to add:
sub DESTROY { my $self = shift; $self->Finish(); }
And the first idea that came to me was your idea of writing a wrapper object. But I didn't like the idea too much. The next idea (and I think this was someone else's idea) was to do it like this:
{ package Class; sub DESTROY { my $self = shift; $self->Finish(); } }
To replace an already existing method you would only need to add no strict and (5.6+) no warnings within the block. As it turns out, and the more advanced have already made this jump, you can just declare:
sub Class::DESTROY { my $self = shift; $self->Finish(); }
Aint it grand? :-)

Replies are listed 'Best First'.
Re (tilly) 2: @ISA, Inheritance, and Class Methods
by tilly (Archbishop) on Mar 13, 2001 at 21:12 UTC
    My solution would be as follows:
    *Class::Destroy = \&Class::Finish;
    which also has the benefit of being a tad faster.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (7)
As of 2024-04-18 18:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found