blib/lib/Test/Reporter/Transport/Net/SMTP/Authen.pm

filter: Statementstmt 13.9% 19 / 136 Branchbran 0.0% 0 / 70 Conditioncond 0.0% 0 / 16 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 41.6% 5 / 12 Podpod 50.0% 2 / 4 totaltotal 10.4% 26 / 248 CC 44 SCAR 63.5
CC
44
Cov
9%
send
992.0
install
56.0
_perform_auth
30.0
CRAP 570.0
↑ Summary
1 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package Test::Reporter::Transport::Net::SMTP::Authen;
4 1 ▶use base 'Test::Reporter::Transport::Net::SMTP';
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use vars qw/$VERSION/;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 $VERSION = '1.02';
7 1 $VERSION = eval $VERSION;
8 1 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 our @EXPORT_OK=qw(install);
10  
11 0 ▶sub install($$$){
Subroutine install: not called CC=7 SCAR=40.3
Pod undocumented
12 0 my ($smtp, $user, $password) = @_;
13 0 ▶ if ( @_ != 3){
Branch: 1 branch
BranchTrueFalseTotal
if (@_ != 3) 0 0 0
14 0 croak( "Usage: install(\$smtp_server, \$user, \$password)" );
15 };
16 0 ▶ unless( $ENV{PERL_CPAN_REPORTER_DIR} || $ENV{HOME} ){
Branch: 1 branch
BranchTrueFalseTotal
unless ($ENV{"PERL_CPAN_REPORTER_DIR"} or $ENV{"HOME"}) 0 0 0
Condition0%0/3
$ENV{"PERL_CPAN_REPORTER_DIR"} or $ENV{"HOME"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$ENV{"PERL_CPAN_REPORTER_DIR"} or $ENV{"HOME"}
$ENV{"PERL_CPAN_REPORTER_DIR"} $ENV{"HOME"}
Truth table0%0/3
A or B
A= $ENV{"PERL_CPAN_REPORTER_DIR"}B= $ENV{"HOME"}
ABresult
1X1
011
000
17 0 require Carp;
18 0 croak( "Please define your enviroment variable PERL_CPAN_REPORTER_DIR or HOME" );
19 }
20 0 ▶ my $reporter_folder = $ENV{PERL_CPAN_REPORTER_DIR} ||= $ENV{HOME} . '/.cpanreporter';
Condition0%0/2
$ENV{"PERL_CPAN_REPORTER_DIR"} ||= $ENV{"HOME"} . '/.cpanreporter'
l!l
00
MC/DC0%0/1
$ENV{"PERL_CPAN_REPORTER_DIR"} ||= $ENV{"HOME"} . '/.cpanreporter'
$ENV{"PERL_CPAN_REPORTER_DIR"}
Truth table0%0/2
A
A= $ENV{"PERL_CPAN_REPORTER_DIR"}
Aresult
11
00
21 0 require File::Path;
22 0 require Carp;
23 0 File::Path->import('mkpath');
24 0 mkpath( $reporter_folder );
25 0 ▶ open my $fh , '>', $reporter_folder .'/config.ini' or Carp::croak( "Can't write config.ini in $reporter_folder $!");
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", $reporter_folder . '/config.ini' or Carp::croak("Can't write config.ini in $reporter_folder $!") 0 0 0
26 0 $a = select ($fh);
27 0 print "edit_report=no\n";
28 0 print "email_from=$user\n";
29 0 print "send_report=yes\n";
30 0 print "smtp_server=$smtp\n";
31 0 print "transport=Net::SMTP::Authen User $user Password $password\n";
32 0 ▶ close $fh or Carp::croak ("Can't finish write $reporter_folder/config.ini $!");
Branch: 1 branch
BranchTrueFalseTotal
close $fh or Carp::croak("Can't finish write $reporter_folder/config.ini $!") 0 0 0
33 0 select $a;
34 0 print STDERR "Writen $reporter_folder/config.ini .\n\tType cpan <CR>\n";
35 0 print STDERR "\to conf test_report 1\n";
36 0 print STDERR "\to conf commit\n";
37 }
38  
39 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
40 0 my ($class, @args) = @_;
41 0 bless { args => \@args } => $class;
42 }
43  
44 0 ▶sub _net_class {
Subroutine _net_class: not called CC=3 SCAR=24.8
45 0 my ($self) = @_;
46 0 ▶ my $class = ref $self ? ref $self : $self;
Branch: 1 branch
BranchTrueFalseTotal
ref $self ? : 0 0 0
47 0 my ($net_class) = ($class =~ /^Test::Reporter::Transport::(.+)\z/);
48 0 ▶ return 'Net::SMTP' if $net_class eq 'Net::SMTP::Authen';
Branch: 1 branch
BranchTrueFalseTotal
if $net_class eq "Net::SMTP::Authen" 0 0 0
49 0 return $net_class;
50 }
51  
52 0 ▶sub _perform_auth{
Subroutine _perform_auth: not called CC=5 SCAR=34.0
53 0 my $self = shift;
54 0 my $transport = shift;
55 0 my $args = $$self{args};
56 0 my %opts = ( @$args );
57
58 0 ▶ my ($user_name) = $opts{'User'} || $opts{'Username'};
Condition0%0/3
$opts{'User'} || $opts{'Username'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts{'User'} || $opts{'Username'}
$opts{'User'} $opts{'Username'}
Truth table0%0/3
A || B
A= $opts{'User'}B= $opts{'Username'}
ABresult
1X1
011
000
59 0 ▶ my ($password) = $opts{'Password'} || $opts{'Pass'};
Condition0%0/3
$opts{'Password'} || $opts{'Pass'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts{'Password'} || $opts{'Pass'}
$opts{'Password'} $opts{'Pass'}
Truth table0%0/3
A || B
A= $opts{'Password'}B= $opts{'Pass'}
ABresult
1X1
011
000
60 0 ▶ die "No user_name" unless $user_name;
Branch: 1 branch
BranchTrueFalseTotal
unless $user_name 0 0 0
61 0 ▶ return 1 if ($self->_net_class() eq 'Net::SMTP::TLS');
Branch: 1 branch
BranchTrueFalseTotal
if $self->_net_class eq "Net::SMTP::TLS" 0 0 0
62 0 return $transport->auth($user_name, $password);
63 }
64  
65  
66 0 ▶sub send {
Subroutine send: not called CC=31 SCAR=69.0
Pod documented
67 0 my ($self, $report, $recipients) = @_;
68 0 ▶ $recipients ||= [];
Condition0%0/2
$recipients ||= []
l!l
00
MC/DC0%0/1
$recipients ||= []
$recipients
Truth table0%0/2
A
A= $recipients
Aresult
11
00
69  
70 0 my $helo = $report->_maildomain(); # XXX: tight -- rjbs, 2008-04-06
71 0 my $from = $report->from();
72 0 my $via = $report->via();
73 0 my @tmprecipients = ();
74 0 my @bad = ();
75 0 my $smtp;
76  
77 my $mx;
78  
79 0 my $transport = $self->_net_class;
80  
81 # Sorry. Tight coupling happened before I got here. -- rjbs, 2008-04-06
82 0 for my $server (@{$report->{_mx}}) {
83 0 eval {
84 0 $smtp = $transport->new(
85 $server,
86 Hello => $helo,
87 Timeout => $report->timeout(),
88 Debug => $report->debug(),
89 $report->transport_args(),
90 );
91 };
92  
93 0 ▶ if (defined $smtp) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $smtp) 0 0 0
94 0 $mx = $server;
95 0 last;
96 }
97 }
98  
99 0 ▶ die "Unable to connect to any MX's: $@" unless $mx && $smtp;
Branch: 1 branch
BranchTrueFalseTotal
unless $mx and $smtp 0 0 0
Condition0%0/3
$mx and $smtp
!ll&&!rl&&r
000
MC/DC0%0/2
$mx and $smtp
$mx $smtp
Truth table0%0/3
A and B
A= $mxB= $smtp
ABresult
0X0
100
111
100  
101 0 my $cc_str;
102 0 ▶ if (@$recipients) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$recipients) 0 0 0
103 0 ▶ if ($mx =~ /(?:^|\.)(?:perl|cpan)\.org$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mx =~ /(?:^|\.)(?:perl|cpan)\.org$/) 0 0 0
104 0 for my $recipient (sort @$recipients) {
105 0 ▶ if ($recipient =~ /(?:@|\.)(?:perl|cpan)\.org$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($recipient =~ /(?:@|\.)(?:perl|cpan)\.org$/) { } 0 0 0
106 0 push @tmprecipients, $recipient;
107 } else {
108 0 push @bad, $recipient;
109 }
110 }
111  
112 0 ▶ if (@bad) {
Branch: 1 branch
BranchTrueFalseTotal
if (@bad) 0 0 0
113 0 warn __PACKAGE__, ": Will not attempt to cc the following recipients since perl.org MX's will not relay for them. Either use Test::Reporter::Transport::Mail::Send, use other MX's, or only cc address ending in cpan.org or perl.org: ${\(join ', ', @bad)}.\n";
114 }
115  
116 0 $recipients = \@tmprecipients;
117 }
118  
119 0 $cc_str = join ', ', @$recipients;
120 0 chomp $cc_str;
121 0 chomp $cc_str;
122 }
123  
124 0 ▶ $via = ', via ' . $via if $via;
Branch: 1 branch
BranchTrueFalseTotal
if $via 0 0 0
125  
126 0 my $envelope_sender = $from;
127 0 $envelope_sender =~ s/\s\([^)]+\)$//; # email only; no name
128  
129 # Net::SMTP returns 1 or undef for pass/fail
130 # Net::SMTP::TLS croaks on fail but may not return 1 on pass
131 # so this closure lets us die on an undef return only for Net::SMTP
132 0 ▶ my $die = sub { die $smtp->message if ref $smtp eq 'Net::SMTP' };
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
if ref $smtp eq "Net::SMTP" 0 0 0
133
134  
135 0 ▶ eval {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { trace(1); $self->_perform_auth($smtp) or &$die(); trace(); $smtp->mail($envelope_sender) or &$die(); trace(); $smtp->to($report->address) or &$die(); trace(); if (@$recipients) { $smtp->cc(@$recipients) or &$die(); } ; trace(); $smtp->data or &$die(); trace(); $smtp->datasend("Date: ", $self->_format_date, "\n") or &$die(); trace(); $smtp->datasend("Subject: ", $report->subject, "\n") or &$die(); trace(); $smtp->datasend("From: $from\n") or &$die(); trace(); $smtp->datasend("To: ", $report->address, "\n") or &$die(); trace(); if (@$recipients) { $smtp->datasend("Cc: $cc_str\n") or &$die(); } ; trace(); $smtp->datasend("Message-ID: ", $report->message_id, "\n") or &$die(); trace(); $smtp->datasend("X-Reported-Via: Test::Reporter $Test::Reporter::VERSION$via\n") or &$die(); trace(); $smtp->datasend("\n") or &$die(); trace(); trace(); $smtp->datasend($report->report) or &$die(); trace(); $smtp->dataend or &$die(); trace(); $smtp->quit or &$die(); trace(); 1 } } or die "$transport - $@" 0 0 0
136 0 trace(1);
137 0 ▶ $self->_perform_auth($smtp) or $die->();
Branch: 1 branch
BranchTrueFalseTotal
$self->_perform_auth($smtp) or &$die() 0 0 0
138 0 trace();
139
140 0 ▶ $smtp->mail($envelope_sender) or $die->();
Branch: 1 branch
BranchTrueFalseTotal
$smtp->mail($envelope_sender) or &$die() 0 0 0
141 0 trace();
142 0 ▶ $smtp->to($report->address) or $die->();
Branch: 1 branch
BranchTrueFalseTotal
$smtp->to($report->address) or &$die() 0 0 0
143 0 trace();
144 0 ▶ if ( @$recipients ) { $smtp->cc(@$recipients) or $die->() };
Branch: 2 branches
BranchTrueFalseTotal
if (@$recipients) 0 0 0
$smtp->cc(@$recipients) or &$die() 0 0 0
145 0 trace();
146 0 ▶ $smtp->data() or $die->();
Branch: 1 branch
BranchTrueFalseTotal
$smtp->data or &$die() 0 0 0
147 0 trace();
148 0 ▶ $smtp->datasend("Date: ", $self->_format_date, "\n") or $die->();
Branch: 1 branch
BranchTrueFalseTotal
$smtp->datasend("Date: ", $self->_format_date, "\n") or &$die() 0 0 0
149 0 trace();
150 0 ▶ $smtp->datasend("Subject: ", $report->subject, "\n") or $die->();
Branch: 1 branch
BranchTrueFalseTotal
$smtp->datasend("Subject: ", $report->subject, "\n") or &$die() 0 0 0
151 0 trace();
152 0 ▶ $smtp->datasend("From: $from\n") or $die->();
Branch: 1 branch
BranchTrueFalseTotal
$smtp->datasend("From: $from\n") or &$die() 0 0 0
153 0 trace();
154 0 ▶ $smtp->datasend("To: ", $report->address, "\n") or $die->();
Branch: 1 branch
BranchTrueFalseTotal
$smtp->datasend("To: ", $report->address, "\n") or &$die() 0 0 0
155 0 trace();
156 0 ▶ if ( @$recipients ) { $smtp->datasend("Cc: $cc_str\n") or $die->() };
Branch: 2 branches
BranchTrueFalseTotal
if (@$recipients) 0 0 0
$smtp->datasend("Cc: $cc_str\n") or &$die() 0 0 0
157 0 trace();
158 0 ▶ $smtp->datasend("Message-ID: ", $report->message_id(), "\n") or $die->();
Branch: 1 branch
BranchTrueFalseTotal
$smtp->datasend("Message-ID: ", $report->message_id, "\n") or &$die() 0 0 0
159 0 trace();
160 0 ▶ $smtp->datasend("X-Reported-Via: Test::Reporter $Test::Reporter::VERSION$via\n") or $die->();
Branch: 1 branch
BranchTrueFalseTotal
$smtp->datasend("X-Reported-Via: Test::Reporter $Test::Reporter::VERSION$via\n") or &$die() 0 0 0
161 0 trace();
162 0 ▶ $smtp->datasend("\n") or $die->();
Branch: 1 branch
BranchTrueFalseTotal
$smtp->datasend("\n") or &$die() 0 0 0
163 0 trace();
164 0 trace();
165 0 ▶ $smtp->datasend($report->report()) or $die->();
Branch: 1 branch
BranchTrueFalseTotal
$smtp->datasend($report->report) or &$die() 0 0 0
166 0 trace();
167 0 ▶ $smtp->dataend() or $die->();
Branch: 1 branch
BranchTrueFalseTotal
$smtp->dataend or &$die() 0 0 0
168 0 trace();
169 0 ▶ $smtp->quit or $die->();
Branch: 1 branch
BranchTrueFalseTotal
$smtp->quit or &$die() 0 0 0
170 0 trace();
171 0 1;
172 } or die "$transport - $@";
173  
174 0 return 1;
175 }
176  
177 1 1;
178  
179 0 ▶sub trace{
Subroutine trace: not called CC=1 SCAR=6.9
Pod undocumented
180 0 my $mess = shift;
181 0 my ($package, $file, $line, $func) = caller 1;
182 0 my ($package1, $file1, $line1, $func1) = caller 0;
183 #print STDERR "[$line:$line1] ";
184 }
185
186 __END__
↑ Summary