Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Re: Re: Extending MIME::Lite

by trs80 (Priest)
on Sep 27, 2003 at 17:52 UTC ( #294660=note: print w/ replies, xml ) Need Help??


in reply to Re: Re: Extending MIME::Lite
in thread Extending MIME::Lite

This reply is to address the change if the modification takes place in MIME::Lite vs. Net::SMTP as my previous post suggests. I think the change in behavior should occur at the send method rather then the send_by_smtp. This would allow future modifications of send methods to accounted for in the same manner. So here is my proposed revised sub send:
# add new global that the top my $SenderOpts = ''; sub send { my $self = shift; if (ref($self)) { ### instance method: my ($method, @args); if (@_) { ### args; use them just t +his once $method = 'send_by_' . shift; @args = @_; } else { ### no args; use defaults $method = "send_by_$Sender"; @args = @{$SenderArgs{$Sender} || []}; } $self->verify_data if $AUTO_VERIFY; ### prevents missing part +s! return $self->$method(@args); } else { ### class method: if (@_) { my @old = ($Sender, @{$SenderArgs{$Sender}}); $Sender = shift; if ( ref($_[0]) eq 'HASH') { $SenderOpts = shift; } $SenderArgs{$Sender} = [@_]; ### remaining args return @old; } else { Carp::croak "class method send must have HOW... arguments\n" +; } } }
Then below in our send_by_smtp method we add:
if ($SenderOpts) { $smtp->auth( $SenderOpts->{auth_username}, $SenderOpts->{auth +_password} ); }
directly after our $smtp object is created.


Comment on Re: Re: Re: Extending MIME::Lite
Select or Download Code
Re: Re: Re: Re: Extending MIME::Lite
by demerphq (Chancellor) on Sep 28, 2003 at 01:17 UTC

    I think the change in behavior should occur at the send method rather then the send_by_smtp.

    I can see what you are getting at here, but it doesnt take into account the full interface of MIME::Lite. We need to handle two distinct cases. The first is that someone uses MIME::Lite->send() to configure the class defaults. The second is that someone calls $mime_obj->send_by_smtp() to override the class defaults or simply because they are doing a quick and dirty, or more likely because they are a beginner and havent groked send() properly.

    Thus whatever processing happens in send() will also have to happen in send_by_smtp (and most likely send_by_sendmail and send_by_sub too). This isn't to say that send() wont be changed, just to say that it doesnt remove the requirement to alter send_by_smtp() as well.


    ---
    demerphq

      First they ignore you, then they laugh at you, then they fight you, then you win.
      -- Gandhi


Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (14)
As of 2014-09-17 16:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (91 votes), past polls