| 1 | package Test::Smoke::Mailer; | ||||||||||||||||||||
| 2 | 3 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 3 | ▶ | use Carp; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | 3 | our $VERSION = '0.016'; | |||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | 3 | ▶ | use Test::Smoke::Mailer::Sendmail; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 3 | ▶ | use Test::Smoke::Mailer::Mail_X; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 3 | ▶ | use Test::Smoke::Mailer::SendEmail; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 3 | ▶ | use Test::Smoke::Mailer::Mail_Sendmail; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | 3 | ▶ | use Test::Smoke::Mailer::MIME_Lite; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | =head1 NAME | ||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | Test::Smoke::Mailer - Factory for objects to send the report. | ||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | =head1 SYNOPSIS | ||||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | use Test::Smoke::Mailer; | ||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | my %args = ( mhowto => 'smtp', mserver => 'smtp.your.domain' ); | ||||||||||||||||||||
| 23 | my $mailer = Test::Smoke::Mailer->new( $ddir, %args ); | ||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | $mailer->mail or die "Problem in mailing: " . $mailer->error; | ||||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | =head1 DESCRIPTION | ||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | This little wrapper still allows you to use the B<sendmail>, B<sendemail>, | ||||||||||||||||||||
| 30 | B<mail> or B<mailx> programs, but prefers to use the B<Mail::Sendmail> | ||||||||||||||||||||
| 31 | module (which comes with this distribution) to send the reports. | ||||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | =head1 METHODS | ||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | =head2 Test::Smoke::Mailer->new( $mailer[, %args] ) | ||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | Can we provide sensible defaults for the mail stuff? | ||||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | mhowto => [Module::Name|sendmail|mail|mailx|sendemail] | ||||||||||||||||||||
| 40 | mserver => an SMTP server || localhost | ||||||||||||||||||||
| 41 | mbin => the full path to the mail binary | ||||||||||||||||||||
| 42 | mto => list of addresses (comma separated!) | ||||||||||||||||||||
| 43 | mfrom => single address | ||||||||||||||||||||
| 44 | mcc => list of addresses (coma separated!) | ||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | =cut | ||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | 3 | our $P5P = 'perl5-porters@perl.org'; | |||||||||||||||||||
| 49 | 3 | our $NOCC_RE = ' (?:PASS\b|FAIL\(X\))'; | |||||||||||||||||||
| 50 | 3 | my %CONFIG = ( | |||||||||||||||||||
| 51 | df_mailer => 'Mail::Sendmail', | ||||||||||||||||||||
| 52 | df_ddir => undef, | ||||||||||||||||||||
| 53 | df_v => 0, | ||||||||||||||||||||
| 54 | df_rptfile => 'mktest.rpt', | ||||||||||||||||||||
| 55 | df_to => 'daily-build-reports@perl.org', | ||||||||||||||||||||
| 56 | df_from => '', | ||||||||||||||||||||
| 57 | df_cc => '', | ||||||||||||||||||||
| 58 | df_swcc => '-c', | ||||||||||||||||||||
| 59 | df_swbcc => '-b', | ||||||||||||||||||||
| 60 | df_bcc => '', | ||||||||||||||||||||
| 61 | df_ccp5p_onfail => 0, | ||||||||||||||||||||
| 62 | df_mserver => 'localhost', | ||||||||||||||||||||
| 63 | df_msuser => undef, | ||||||||||||||||||||
| 64 | df_mspass => undef, | ||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | df_mailbin => 'mail', | ||||||||||||||||||||
| 67 | mail => [qw( bcc cc mailbin )], | ||||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | df_mailxbin => 'mailx', | ||||||||||||||||||||
| 70 | mailx => [qw( bcc cc mailxbin swcc swbcc )], | ||||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | df_sendemailbin => 'sendemail', | ||||||||||||||||||||
| 73 | sendemail => [qw( from bcc cc sendemailbin mserver msuser mspass )], | ||||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | df_sendmailbin => 'sendmail', | ||||||||||||||||||||
| 76 | sendmail => [qw( from bcc cc sendmailbin )], | ||||||||||||||||||||
| 77 | 'Mail::Sendmail' => [qw( from bcc cc mserver )], | ||||||||||||||||||||
| 78 | 'MIME::Lite' => [qw( from bcc cc mserver msuser mspass )], | ||||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | valid_mailer => { | ||||||||||||||||||||
| 81 | sendmail => 1, | ||||||||||||||||||||
| 82 | mail => 1, | ||||||||||||||||||||
| 83 | mailx => 1, | ||||||||||||||||||||
| 84 | sendemail => 1, | ||||||||||||||||||||
| 85 | 'Mail::Sendmail' => 1, | ||||||||||||||||||||
| 86 | 'MIME::Lite' => 1, | ||||||||||||||||||||
| 87 | }, | ||||||||||||||||||||
| 88 | ); | ||||||||||||||||||||
| 89 | |||||||||||||||||||||
| 90 | 0 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: not called CC=11 SCAR=48.8
Pod
documented
| |||||||||||||||||||||
| 91 | 0 | my $class = shift; | |||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | 0 | ▶ | my $mailer = shift || $CONFIG{df_mailer}; | ||||||||||||||||||
|
Condition0%0/3
shift() || $CONFIG{'df_mailer'}
MC/DC0%0/2
shift() || $CONFIG{'df_mailer'}
shift()
$CONFIG{'df_mailer'}
Truth table0%0/3
A || B
A= shift()B= $CONFIG{'df_mailer'}
| |||||||||||||||||||||
| 94 | |||||||||||||||||||||
| 95 | 0 | ▶ | if (! exists $CONFIG{valid_mailer}->{ $mailer } ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 96 | 0 | croak( "Invalid mailer '$mailer'" ); | |||||||||||||||||||
| 97 | }; | ||||||||||||||||||||
| 98 | |||||||||||||||||||||
| 99 | 0 | ▶ | my %args_raw = @_ ? UNIVERSAL::isa( $_[0], 'HASH' ) ? %{ $_[0] } : @_ : (); | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 100 | |||||||||||||||||||||
| 101 | my %args = map { | ||||||||||||||||||||
| 102 | 0 | ( my $key = $_ ) =~ s/^-?(.+)$/lc $1/e; | |||||||||||||||||||
| 103 | 0 | ( $key => $args_raw{ $_ } ); | |||||||||||||||||||
| 104 | } keys %args_raw; | ||||||||||||||||||||
| 105 | |||||||||||||||||||||
| 106 | my %fields = map { | ||||||||||||||||||||
| 107 | 0 | ▶ | my $value = exists $args{$_} ? $args{ $_ } : $CONFIG{ "df_$_" }; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 108 | 0 | ( $_ => $value ) | |||||||||||||||||||
| 109 | 0 | } ( rptfile => v => ddir => to => ccp5p_onfail => @{ $CONFIG{ $mailer } } ); | |||||||||||||||||||
| 110 | 0 | $fields{ddir} = File::Spec->rel2abs( $fields{ddir} ); | |||||||||||||||||||
| 111 | |||||||||||||||||||||
| 112 | DO_NEW: { | ||||||||||||||||||||
| 113 | 0 | local $_ = $mailer; | |||||||||||||||||||
| 114 | |||||||||||||||||||||
| 115 | 0 | ▶ | /^sendmail$/ && do { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 116 | 0 | return Test::Smoke::Mailer::Sendmail->new(%fields); | |||||||||||||||||||
| 117 | }; | ||||||||||||||||||||
| 118 | 0 | ▶ | /^mailx?$/ && do { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 119 | 0 | return Test::Smoke::Mailer::Mail_X->new(%fields); | |||||||||||||||||||
| 120 | }; | ||||||||||||||||||||
| 121 | 0 | ▶ | /^sendemail?$/ && do { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 122 | 0 | return Test::Smoke::Mailer::SendEmail->new(%fields); | |||||||||||||||||||
| 123 | }; | ||||||||||||||||||||
| 124 | 0 | ▶ | /^Mail::Sendmail$/ && do { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 125 | 0 | return Test::Smoke::Mailer::Mail_Sendmail->new(%fields); | |||||||||||||||||||
| 126 | }; | ||||||||||||||||||||
| 127 | 0 | ▶ | /^MIME::Lite$/ && do { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 128 | 0 | return Test::Smoke::Mailer::MIME_Lite->new(%fields); | |||||||||||||||||||
| 129 | }; | ||||||||||||||||||||
| 130 | } | ||||||||||||||||||||
| 131 | |||||||||||||||||||||
| 132 | } | ||||||||||||||||||||
| 133 | |||||||||||||||||||||
| 134 | =head2 Test::Smoke::Mailer->config( $key[, $value] ) | ||||||||||||||||||||
| 135 | |||||||||||||||||||||
| 136 | C<config()> is an interface to the package lexical C<%CONFIG>, | ||||||||||||||||||||
| 137 | which holds all the default values for the C<new()> arguments. | ||||||||||||||||||||
| 138 | |||||||||||||||||||||
| 139 | With the special key B<all_defaults> this returns a reference | ||||||||||||||||||||
| 140 | to a hash holding all the default values. | ||||||||||||||||||||
| 141 | |||||||||||||||||||||
| 142 | =cut | ||||||||||||||||||||
| 143 | |||||||||||||||||||||
| 144 | 0 | ▶ | sub config { | ||||||||||||||||||
|
Subroutine
config: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||
| 145 | 0 | my $dummy = shift; | |||||||||||||||||||
| 146 | |||||||||||||||||||||
| 147 | 0 | my $key = lc shift; | |||||||||||||||||||
| 148 | |||||||||||||||||||||
| 149 | 0 | ▶ | if ( $key eq 'all_defaults' ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 150 | my %default = map { | ||||||||||||||||||||
| 151 | 0 | my( $pass_key ) = $_ =~ /^df_(.+)/; | |||||||||||||||||||
| 152 | 0 | ( $pass_key => $CONFIG{ $_ } ); | |||||||||||||||||||
| 153 | } grep /^df_/ => keys %CONFIG; | ||||||||||||||||||||
| 154 | 0 | return \%default; | |||||||||||||||||||
| 155 | } | ||||||||||||||||||||
| 156 | |||||||||||||||||||||
| 157 | 0 | ▶ | return undef unless exists $CONFIG{ "df_$key" }; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 158 | |||||||||||||||||||||
| 159 | 0 | ▶ | $CONFIG{ "df_$key" } = shift if @_; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 160 | |||||||||||||||||||||
| 161 | 0 | return $CONFIG{ "df_$key" }; | |||||||||||||||||||
| 162 | } | ||||||||||||||||||||
| 163 | |||||||||||||||||||||
| 164 | =head1 COPYRIGHT | ||||||||||||||||||||
| 165 | |||||||||||||||||||||
| 166 | (c) 2002-2013, All rights reserved. | ||||||||||||||||||||
| 167 | |||||||||||||||||||||
| 168 | * Abe Timmerman <abeltje@cpan.org> | ||||||||||||||||||||
| 169 | |||||||||||||||||||||
| 170 | This library is free software; you can redistribute it and/or modify | ||||||||||||||||||||
| 171 | it under the same terms as Perl itself. | ||||||||||||||||||||
| 172 | |||||||||||||||||||||
| 173 | See: | ||||||||||||||||||||
| 174 | |||||||||||||||||||||
| 175 | * <http://www.perl.com/perl/misc/Artistic.html>, | ||||||||||||||||||||
| 176 | * <http://www.gnu.org/copyleft/gpl.html> | ||||||||||||||||||||
| 177 | |||||||||||||||||||||
| 178 | This program is distributed in the hope that it will be useful, | ||||||||||||||||||||
| 179 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||||||||||||||||
| 180 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||||||||||||||||||||
| 181 | |||||||||||||||||||||
| 182 | =cut | ||||||||||||||||||||