in reply to Can I use the OO DESTROY method ... for a good cause
Hi,
in addition to what was said before. This snippet should show you that you don't need to explicitly call DESTROY:
#!/usr/bin/perl use strict; use warnings; use 5.010; use Email::Stuffer; { package MyMail; use parent 'Email::MIME'; sub DESTROY { my ($self) = @_; say "in DESTROY"; } } # Get a Email::MIME object easily my $email = Email::Stuffer->from('huhu@yahoo.de') ->to('you@yahoo.de') ->text_body('Hi you!') ->email; foreach my $nr (1..2) { my $e = MyMail->new($email->as_string); say "Should be before DESTROY"; } say "Atfter Loop";
As soon as your last reference to the object goes out of scope the DESTROY method gets called.
Regards
McA
|
|---|