| 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
| |||||||||||||||||||||||||||||
| 14 | 0 | croak( "Usage: install(\$smtp_server, \$user, \$password)" ); | |||||||||||||||||||||||||||
| 15 | }; | ||||||||||||||||||||||||||||
| 16 | 0 | ▶ | unless( $ENV{PERL_CPAN_REPORTER_DIR} || $ENV{HOME} ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$ENV{"PERL_CPAN_REPORTER_DIR"} or $ENV{"HOME"}
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"}
| |||||||||||||||||||||||||||||
| 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'
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"}
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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'}
MC/DC0%0/2
$opts{'User'} || $opts{'Username'}
$opts{'User'}
$opts{'Username'}
Truth table0%0/3
A || B
A= $opts{'User'}B= $opts{'Username'}
| |||||||||||||||||||||||||||||
| 59 | 0 | ▶ | my ($password) = $opts{'Password'} || $opts{'Pass'}; | ||||||||||||||||||||||||||
|
Condition0%0/3
$opts{'Password'} || $opts{'Pass'}
MC/DC0%0/2
$opts{'Password'} || $opts{'Pass'}
$opts{'Password'}
$opts{'Pass'}
Truth table0%0/3
A || B
A= $opts{'Password'}B= $opts{'Pass'}
| |||||||||||||||||||||||||||||
| 60 | 0 | ▶ | die "No user_name" unless $user_name; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | 0 | ▶ | return 1 if ($self->_net_class() eq 'Net::SMTP::TLS'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 ||= []
MC/DC0%0/1
$recipients ||= []
$recipients
Truth table0%0/2
A
A= $recipients
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition0%0/3
$mx and $smtp
MC/DC0%0/2
$mx and $smtp
$mx
$smtp
Truth table0%0/3
A and B
A= $mxB= $smtp
| |||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 0 | my $cc_str; | |||||||||||||||||||||||||||
| 102 | 0 | ▶ | if (@$recipients) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 103 | 0 | ▶ | if ($mx =~ /(?:^|\.)(?:perl|cpan)\.org$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | 0 | for my $recipient (sort @$recipients) { | |||||||||||||||||||||||||||
| 105 | 0 | ▶ | if ($recipient =~ /(?:@|\.)(?:perl|cpan)\.org$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | 0 | push @tmprecipients, $recipient; | |||||||||||||||||||||||||||
| 107 | } else { | ||||||||||||||||||||||||||||
| 108 | 0 | push @bad, $recipient; | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 0 | ▶ | if (@bad) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | 0 | ▶ | eval { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 136 | 0 | trace(1); | |||||||||||||||||||||||||||
| 137 | 0 | ▶ | $self->_perform_auth($smtp) or $die->(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 138 | 0 | trace(); | |||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | 0 | ▶ | $smtp->mail($envelope_sender) or $die->(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 141 | 0 | trace(); | |||||||||||||||||||||||||||
| 142 | 0 | ▶ | $smtp->to($report->address) or $die->(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 143 | 0 | trace(); | |||||||||||||||||||||||||||
| 144 | 0 | ▶ | if ( @$recipients ) { $smtp->cc(@$recipients) or $die->() }; | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 145 | 0 | trace(); | |||||||||||||||||||||||||||
| 146 | 0 | ▶ | $smtp->data() or $die->(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 147 | 0 | trace(); | |||||||||||||||||||||||||||
| 148 | 0 | ▶ | $smtp->datasend("Date: ", $self->_format_date, "\n") or $die->(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 149 | 0 | trace(); | |||||||||||||||||||||||||||
| 150 | 0 | ▶ | $smtp->datasend("Subject: ", $report->subject, "\n") or $die->(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 151 | 0 | trace(); | |||||||||||||||||||||||||||
| 152 | 0 | ▶ | $smtp->datasend("From: $from\n") or $die->(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 153 | 0 | trace(); | |||||||||||||||||||||||||||
| 154 | 0 | ▶ | $smtp->datasend("To: ", $report->address, "\n") or $die->(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 155 | 0 | trace(); | |||||||||||||||||||||||||||
| 156 | 0 | ▶ | if ( @$recipients ) { $smtp->datasend("Cc: $cc_str\n") or $die->() }; | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 157 | 0 | trace(); | |||||||||||||||||||||||||||
| 158 | 0 | ▶ | $smtp->datasend("Message-ID: ", $report->message_id(), "\n") or $die->(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 159 | 0 | trace(); | |||||||||||||||||||||||||||
| 160 | 0 | ▶ | $smtp->datasend("X-Reported-Via: Test::Reporter $Test::Reporter::VERSION$via\n") or $die->(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 161 | 0 | trace(); | |||||||||||||||||||||||||||
| 162 | 0 | ▶ | $smtp->datasend("\n") or $die->(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 163 | 0 | trace(); | |||||||||||||||||||||||||||
| 164 | 0 | trace(); | |||||||||||||||||||||||||||
| 165 | 0 | ▶ | $smtp->datasend($report->report()) or $die->(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 166 | 0 | trace(); | |||||||||||||||||||||||||||
| 167 | 0 | ▶ | $smtp->dataend() or $die->(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 168 | 0 | trace(); | |||||||||||||||||||||||||||
| 169 | 0 | ▶ | $smtp->quit or $die->(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||