| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Email::Sender::Transport::SMTP::Persistent 2.500; | 
| 2 |  |  |  |  |  |  | # ABSTRACT: an SMTP client that stays online | 
| 3 |  |  |  |  |  |  |  | 
| 4 | 1 |  |  | 1 |  | 1229 | use Moo; | 
|  | 1 |  |  |  |  | 4 |  | 
|  | 1 |  |  |  |  | 11 |  | 
| 5 |  |  |  |  |  |  | extends 'Email::Sender::Transport::SMTP'; | 
| 6 |  |  |  |  |  |  |  | 
| 7 |  |  |  |  |  |  | #pod =head1 DESCRIPTION | 
| 8 |  |  |  |  |  |  | #pod | 
| 9 |  |  |  |  |  |  | #pod The stock L reconnects each time it sends a | 
| 10 |  |  |  |  |  |  | #pod message.  This transport only reconnects when the existing connection fails. | 
| 11 |  |  |  |  |  |  | #pod | 
| 12 |  |  |  |  |  |  | #pod =cut | 
| 13 |  |  |  |  |  |  |  | 
| 14 | 1 |  |  | 1 |  | 410 | use Net::SMTP; | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 269 |  | 
| 15 |  |  |  |  |  |  |  | 
| 16 |  |  |  |  |  |  | has _cached_client => ( | 
| 17 |  |  |  |  |  |  | is => 'rw', | 
| 18 |  |  |  |  |  |  | ); | 
| 19 |  |  |  |  |  |  |  | 
| 20 |  |  |  |  |  |  | sub _smtp_client { | 
| 21 | 0 |  |  | 0 |  |  | my ($self) = @_; | 
| 22 |  |  |  |  |  |  |  | 
| 23 | 0 | 0 |  |  |  |  | if (my $client = $self->_cached_client) { | 
| 24 | 0 | 0 |  |  |  |  | return $client if eval { $client->reset; $client->ok; }; | 
|  | 0 |  |  |  |  |  |  | 
|  | 0 |  |  |  |  |  |  | 
| 25 |  |  |  |  |  |  |  | 
| 26 | 0 |  | 0 |  |  |  | my $error = $@ | 
| 27 |  |  |  |  |  |  | || 'error resetting cached SMTP connection: ' . $client->message; | 
| 28 |  |  |  |  |  |  |  | 
| 29 | 0 |  |  |  |  |  | Carp::carp($error); | 
| 30 |  |  |  |  |  |  | } | 
| 31 |  |  |  |  |  |  |  | 
| 32 | 0 |  |  |  |  |  | my $client = $self->SUPER::_smtp_client; | 
| 33 |  |  |  |  |  |  |  | 
| 34 | 0 |  |  |  |  |  | $self->_cached_client($client); | 
| 35 |  |  |  |  |  |  |  | 
| 36 | 0 |  |  |  |  |  | return $client; | 
| 37 |  |  |  |  |  |  | } | 
| 38 |  |  |  |  |  |  |  | 
| 39 |  |  |  | 0 |  |  | sub _message_complete { } | 
| 40 |  |  |  |  |  |  |  | 
| 41 |  |  |  |  |  |  | #pod =method disconnect | 
| 42 |  |  |  |  |  |  | #pod | 
| 43 |  |  |  |  |  |  | #pod   $transport->disconnect; | 
| 44 |  |  |  |  |  |  | #pod | 
| 45 |  |  |  |  |  |  | #pod This method sends an SMTP QUIT command and destroys the SMTP client, if on | 
| 46 |  |  |  |  |  |  | #pod exists and is connected. | 
| 47 |  |  |  |  |  |  | #pod | 
| 48 |  |  |  |  |  |  | #pod =cut | 
| 49 |  |  |  |  |  |  |  | 
| 50 |  |  |  |  |  |  | sub disconnect { | 
| 51 | 0 |  |  | 0 | 1 |  | my ($self) = @_; | 
| 52 | 0 | 0 |  |  |  |  | return unless $self->_cached_client; | 
| 53 | 0 |  |  |  |  |  | $self->_cached_client->quit; | 
| 54 | 0 |  |  |  |  |  | $self->_cached_client(undef); | 
| 55 |  |  |  |  |  |  | } | 
| 56 |  |  |  |  |  |  |  | 
| 57 | 1 |  |  | 1 |  | 9 | no Moo; | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 6 |  | 
| 58 |  |  |  |  |  |  | 1; | 
| 59 |  |  |  |  |  |  |  | 
| 60 |  |  |  |  |  |  | __END__ |