in reply to Re: Extending MIME::Lite
in thread Extending MIME::Lite
I'm thinking of intercepting the hashref before calling new. So that
require Net::SMTP; my $smtp = MIME::Lite::SMTP->new(@args) or Carp::croak("Failed to connect to mail server: $!\n");
becomes something like...
require Net::SMTP; my $smtp; if (ref $args[0]) { $opts = shift @args; # handle special cases, and finally resulting in a usable valu +e # in $smtp. } else { $smtp = MIME::Lite::SMTP->new(@args) or Carp::croak("Failed to connect to mail server: $!\n"); }
So before MIME::Lite::SMTP even gets called @args has been precleaned as appropriate. This would allow special cases like having a list of SMTP hosts that are tried until one lets us in, or handling authentication, or turning Debug on in Net::SMTP without having to do the ugly Net::SMTP->new(undef,Debug=>1) in the user code (inside MIME::Lite its ok to do this, as in there its unlikely to cause trouble to a newbie).
Also I agree quite a bit with your points about positional arguments. The only quibble I have is from Perls flexibility with arguments and weakish typing. You can often extend positional arguments by getting creative with types. For instance the trick above works out because its extremely unlikely that somebody is using a blessed reference as a hostname. In fact I could get a lot more picky and check that the ref is a HASH and that if it is a hash that stringification is not overloaded. This would result in total backwards compatibility while still allowing extension.
Cheers,
First they ignore you, then they laugh at you, then they fight you, then you win.
-- Gandhi
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Extending MIME::Lite
by trs80 (Priest) on Sep 27, 2003 at 14:24 UTC | |
by demerphq (Chancellor) on Sep 28, 2003 at 01:04 UTC | |
|
Re: Re: Re: Extending MIME::Lite
by trs80 (Priest) on Sep 27, 2003 at 17:52 UTC | |
by demerphq (Chancellor) on Sep 28, 2003 at 01:17 UTC |