File Coverage

blib/lib/Authen/Simple/SMTP.pm
Criterion Covered Total %
statement 15 28 53.5
branch 0 10 0.0
condition 0 4 0.0
subroutine 5 6 83.3
pod 1 1 100.0
total 21 49 42.8


line stmt bran cond sub pod time code
1             package Authen::Simple::SMTP;
2              
3 1     1   2431 use strict;
  1         2  
  1         41  
4 1     1   6 use warnings;
  1         2  
  1         35  
5 1     1   5 use base 'Authen::Simple::Adapter';
  1         3  
  1         352  
6              
7 1     1   1028 use Net::SMTP;
  1         11160  
  1         77  
8 1     1   14 use Params::Validate qw[];
  1         3  
  1         489  
9              
10             our $VERSION = 0.2;
11              
12             __PACKAGE__->options({
13             host => {
14             type => Params::Validate::SCALAR,
15             default => 'localhost',
16             optional => 1
17             },
18             port => {
19             type => Params::Validate::SCALAR,
20             default => 25,
21             optional => 1
22             },
23             timeout => {
24             type => Params::Validate::SCALAR,
25             default => 60,
26             optional => 1
27             }
28             });
29              
30             sub check {
31 0     0 1   my ( $self, $username, $password ) = @_;
32              
33 0           my $connection = Net::SMTP->new(
34             Host => $self->host,
35             Port => $self->port,
36             Timeout => $self->timeout
37             );
38              
39 0 0         unless ( defined $connection ) {
40              
41 0           my $host = $self->host;
42 0   0       my $reason = $@ || $! || 'Unknown reason';
43              
44 0 0         $self->log->error( qq/Failed to connect to '$host'. Reason: '$reason'/ )
45             if $self->log;
46              
47 0           return 0;
48             }
49              
50 0 0         unless ( $connection->auth( $username, $password ) ) {
51              
52 0   0       chomp( my $message = $connection->message || 'Unknown reason' );
53              
54 0 0         $self->log->debug( qq/Failed to authenticate user '$username'. Reason: '$message'/ )
55             if $self->log;
56              
57 0           return 0;
58             }
59              
60 0 0         $self->log->debug( qq/Successfully authenticated user '$username'./ )
61             if $self->log;
62              
63 0           return 1;
64             }
65              
66             1;
67              
68             __END__