On Mon, Apr 09, 2012 at 04:13:36PM +0800, xiaolan wrote:
> Hi,
>
> I just want to send email using MIME::Lite with Net::SMTP::SSL.
> But MIME::Lite is going only with Net::SMTP by default.
> So I searched and found a hack:
>
> use Net::SMTP::SSL;
> BEGIN { @MIME::Lite::SMTP::ISA = qw(Net::SMTP::SSL); }
>
> This does work, now I can send messages with SMTPs.
> But how does this work? Thank you.
>
ISA provides inheritance in OO Perl; see [1],[2]
The default MIME::Lite package - I have v3.028 - has
@ISA = qw(Net::SMTP);
so MIME::Lite ordinarily inherits Net::SMTP's methods.
The code
BEGIN { @MIME::Lite::SMTP::ISA = qw(Net::SMTP::SSL); }
firstly is a BEGIN block which has special rules for point of
execution [3]. It will be executed as soon as it is encountered.
This BEGIN block overrides MIME::Lite::SMTP's ISA array with Net::SMTP::SSL.
So instead of using Net::SMTP's methods you use Net::SMTP::SSL's methods.
I do puzzle over how stable this approach is. I would be concerned about
MIME::Lite loading after this BEGIN block is executed and overwriting the
inheritance back to Net::SMTP.
So I would be tempted to just have
@MIME::Lite::SMTP::ISA = qw(Net::SMTP::SSL);
as a line of code in the appropriate place to ensure order of processing.
Comments please.
Kind Regards
Lesley
[1]http://perldoc.perl.org/perlboot.html
[2]http://perldoc.perl.org/perltoot.html
[3]http://perldoc.perl.org/perlmod.html#BEGIN,-UNITCHECK,-CHECK,-INIT-and-END
> Regards.
>
> --
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
> http://learn.perl.org/
>
>
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/