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? :-)
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.