ZofCMS/Plugin/FormMailer.pm

filter: Statementstmt 23.0% 12 / 52 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 50.0% 3 / 6 Podpod n/a totaltotal 18.2% 15 / 82 CC 13 SCAR 48.8
CC
13
Cov
16%
_do
182.0
_key
2.0
_defaults
2.0
CRAP 131.8
« ZofCMS/Plugin/CurrentPageURI.pm ↑ Summary ZofCMS/Plugin/SendFile.pm »
1 package App::ZofCMS::Plugin::FormMailer;
2  
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 our $VERSION = '1.001010'; # VERSION
7  
8 1 ▶use base 'App::ZofCMS::Plugin::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 require File::Spec;
10 0 ▶sub _key { 'plug_form_mailer' }
Subroutine _key: not called CC=1 SCAR=6.9
11 0 ▶sub _defaults {
Subroutine _defaults: not called CC=1 SCAR=6.9
12 return (
13 0 trigger => [ qw/d plug_form_mailer/ ],
14 subject => 'FormMailer',
15 ok_key => 't',
16 );
17 }
18  
19 0 ▶sub _do {
Subroutine _do: not called CC=13 SCAR=52.0
20 0 my ( $self, $conf, $template, $query, $config ) = @_;
21  
22 0 my $trigger = $template;
23 0 ▶ for ( @{ $conf->{trigger} || [] } ) {
Condition0%0/2
$conf->{'trigger'} || []
l!l
00
MC/DC0%0/1
$conf->{'trigger'} || []
$conf->{'trigger'}
Truth table0%0/2
A
A= $conf->{'trigger'}
Aresult
11
00
24 0 $trigger = $trigger->{$_};
25 }
26 return
27 0 ▶ unless $trigger;
Branch: 1 branch
BranchTrueFalseTotal
unless $trigger 0 0 0
28  
29 0 my %query = %$query;
30 defined or $_ = ''
31 0 ▶ for values %query;
Branch: 1 branch
BranchTrueFalseTotal
defined $_ or $_ = "" 0 0 0
32  
33 0 my $format = $conf->{format};
34 {
35 0 ▶ if ( ref $format ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $format) 0 0 0
36 0 my $file_name = File::Spec->catfile( $config->conf->{templates}, $$format );
37 0 my $fh;
38 0 ▶ unless ( open $fh, '<', $file_name ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (open $fh, "<", $file_name) 0 0 0
39 0 $template->{t}{plug_form_mailer_error} = "Failed to open $file_name [$!]";
40 0 $format = '';
41 0 last;
42 }
43  
44 0 $format = do { local $/; <$fh> };
45 }
46 }
47  
48 0 my %specials = (
49 time => scalar localtime(),
50 host => $config->cgi->remote_host,
51 );
52 0 $format =~ s/\{:\{([^}]+)}:}/$query{$1}/g;
53 0 $format =~ s/\{:\[(time|host)\]:}/$specials{$1}/g;
54  
55 0 require Mail::Send;
56  
57 $conf->{to} = [ $conf->{to} ]
58 0 ▶ unless ref $conf->{to};
Branch: 1 branch
BranchTrueFalseTotal
unless ref $conf->{"to"} 0 0 0
59  
60 0 my $msg = Mail::Send->new;
61 0 $msg->to( @{ $conf->{to} } );
62 0 $msg->subject( $conf->{subject} );
63  
64 $msg->set('From', $conf->{from})
65 if defined $conf->{from}
66 0 ▶ and length $conf->{from};
Branch: 1 branch
BranchTrueFalseTotal
if defined $conf->{"from"} and length $conf->{"from"} 0 0 0
Condition0%0/3
defined $conf->{"from"} and length $conf->{"from"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $conf->{"from"} and length $conf->{"from"}
defined $conf->{"from"} length $conf->{"from"}
Truth table0%0/3
A and B
A= defined $conf->{"from"}B= length $conf->{"from"}
ABresult
0X0
100
111
67  
68 0 $Mail::Mailer::testfile::config{outfile} = 'mailer.testfile';
69 0 ▶ my $fh = $msg->open( $conf->{mailer} ? $conf->{mailer} : () );
Branch: 1 branch
BranchTrueFalseTotal
$conf->{'mailer'} ? : 0 0 0
70 0 print $fh $format;
71 0 $fh->close;
72  
73 0 $template->{ $conf->{ok_key} }{plug_form_mailer_ok} = 1;
74 0 ▶ if ( defined $conf->{ok_redirect} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $conf->{"ok_redirect"}) 0 0 0
75 0 print $config->cgi->redirect( $conf->{ok_redirect} );
76 0 exit;
77 }
78 }
79  
80 1 1;
81 __END__
« ZofCMS/Plugin/CurrentPageURI.pm ↑ Summary ZofCMS/Plugin/SendFile.pm »