On Mon, Apr 09, 2012 at 12:59:04PM +0300, Shlomi Fish wrote: > Hi xiaolan, > > On Mon, 9 Apr 2012 16:13:36 +0800 > xiaolan <practicalp...@gmail.com> 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. > > > > The @ISA variable (which is specific for each package) determines which > packages > the current package inherits from. Note that in Perl 5, classes are > implemented as packages. One can mutate the inheritance graph at run-time by > changing the @ISA's of the various packages involved. This is usually not > recommended, but as you demonstrate here - it is still useful. > > There's more information about it in the various perldocs, and some older > tutorials (and the book Modern Perl covers it too), but there are more > recommended ways to initially populate the packages’ @ISA, namely the > extends() > function when using Moose or friends, and "use base" (and the more modern "use > parent") when not. >
The parent examples on perldoc.perl.org[1] show this package Baz; use parent qw(Foo Bar); is 'mostly similar' to package Baz; BEGIN { require Foo; require Bar; push @ISA, qw(Foo Bar); } which nicely answers my worry about the override being overridden. It seems that parent causes Baz to inherit Foo and Bar ; it doesn't override anything inherited by Foo or Bar and I don't see anything in the base[2] and parent documentation to show eiher can do this. xiaolan's orginal code overwrites the parent classes of MIME::Lite::SMTP to access the SSL socket layer. It's not inheriting but altering the inheritance of a class/module being used. To be safe xiaolan's BEGIN code should have BEGIN{ ## make sure required modules are loaded require MIME::Lite; require Net::SMTP::SSL; ## override the default socket layer in MIME::Lite @MIME::Lite::SMTP::ISA = qw(Net::SMTP::SSL); } Kind regards Lesley [1]http://perldoc.perl.org/parent.html [2]http://perldoc.perl.org/base.html -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/