ZofCMS/Plugin/QuickNote.pm

filter: Statementstmt 11.9% 11 / 92 Branchbran 0.0% 0 / 38 Conditioncond 0.0% 0 / 32 MC/DCmcdc 0.0% 0 / 19 Subroutinesub 30.0% 3 / 10 Podpod 0.0% 0 / 2 totaltotal 7.2% 14 / 193 CC 35 SCAR 53.6
CC
35
Cov
7%
_process_note
420.0
process
72.0
_send_mail
42.0
CRAP 211.8
« ZofCMS/Plugin/DBI.pm ↑ Summary ZofCMS/Plugin/FileList.pm »
1 package App::ZofCMS::Plugin::QuickNote;
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 HTML::Template;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 0 ▶sub new { return bless {}, shift }
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
11  
12 0 ▶sub process {
Subroutine process: not called CC=8 SCAR=42.8
Pod undocumented
13 0 my ( $self, $template, $query, $config ) = @_;
14  
15 return
16 0 ▶ unless $template->{quicknote};
Branch: 1 branch
BranchTrueFalseTotal
unless $template->{"quicknote"} 0 0 0
17  
18 0 my $qn_conf = delete $template->{quicknote};
19  
20 0 $qn_conf->{sender_host} = $config->cgi->remote_host;
21  
22 0 my $html_template = $self->_setup_form( $query );
23  
24 0 ▶ if ( defined $query->{quicknote_username}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $query->{"quicknote_username"} and $query->{"quicknote_username"} eq "your full name") 0 0 0
Condition0%0/3
defined $query->{"quicknote_username"} and $query->{"quicknote_username"} eq "your full name"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $query->{"quicknote_username"} and $query->{"quicknote_username"} eq "your full name"
defined $query->{"quicknote_username"} $query->{"quicknote_username"} eq "your full name"
Truth table0%0/3
A and B
A= defined $query->{"quicknote_username"}B= $query->{"quicknote_username"} eq "your full name"
ABresult
0X0
100
111
25 and $query->{quicknote_username} eq 'your full name'
26 ) {
27 0 my $is_success = $self->_process_note( $qn_conf, $html_template, $query );
28 0 ▶ if ( defined $qn_conf->{on_error} and not $is_success ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $qn_conf->{"on_error"} and not $is_success) 0 0 0
Condition0%0/3
defined $qn_conf->{"on_error"} and not $is_success
!ll&&!rl&&r
000
MC/DC0%0/2
defined $qn_conf->{"on_error"} and not $is_success
defined $qn_conf->{"on_error"} not $is_success
Truth table0%0/3
A and not(B)
A= defined $qn_conf->{"on_error"}B= not $is_success
ABresult
0X0
100
111
29 0 $template->{t}{ $qn_conf->{on_error} } = 1;
30 }
31  
32 0 ▶ if ( defined $qn_conf->{on_success} and $is_success ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $qn_conf->{"on_success"} and $is_success) 0 0 0
Condition0%0/3
defined $qn_conf->{"on_success"} and $is_success
!ll&&!rl&&r
000
MC/DC0%0/2
defined $qn_conf->{"on_success"} and $is_success
defined $qn_conf->{"on_success"} $is_success
Truth table0%0/3
A and B
A= defined $qn_conf->{"on_success"}B= $is_success
ABresult
0X0
100
111
33 0 $template->{t}{ $qn_conf->{on_success} } = 1;
34 }
35 }
36  
37 0 $template->{t}{quicknote} = $html_template->output;
38  
39 0 return 1;
40 }
41  
42 0 ▶sub _process_note {
Subroutine _process_note: not called CC=20 SCAR=60.4
43 0 my ( $self, $qn_conf, $template, $query ) = @_;
44  
45 0 ▶ $qn_conf->{name_max} ||= 100;
Condition0%0/2
$qn_conf->{"name_max"} ||= 100
l!l
00
MC/DC0%0/1
$qn_conf->{"name_max"} ||= 100
$qn_conf->{"name_max"}
Truth table0%0/2
A
A= $qn_conf->{"name_max"}
Aresult
11
00
46 0 ▶ $qn_conf->{email_max} ||= 200;
Condition0%0/2
$qn_conf->{"email_max"} ||= 200
l!l
00
MC/DC0%0/1
$qn_conf->{"email_max"} ||= 200
$qn_conf->{"email_max"}
Truth table0%0/2
A
A= $qn_conf->{"email_max"}
Aresult
11
00
47 0 ▶ $qn_conf->{message_max} ||= 10000;
Condition0%0/2
$qn_conf->{"message_max"} ||= 10000
l!l
00
MC/DC0%0/1
$qn_conf->{"message_max"} ||= 10000
$qn_conf->{"message_max"}
Truth table0%0/2
A
A= $qn_conf->{"message_max"}
Aresult
11
00
48 0 ▶ $qn_conf->{must_name} ||= 0;
Condition0%0/2
$qn_conf->{"must_name"} ||= 0
l!l
00
MC/DC0%0/1
$qn_conf->{"must_name"} ||= 0
$qn_conf->{"must_name"}
Truth table0%0/2
A
A= $qn_conf->{"must_name"}
Aresult
11
00
49 0 ▶ $qn_conf->{must_email} ||= 0;
Condition0%0/2
$qn_conf->{"must_email"} ||= 0
l!l
00
MC/DC0%0/1
$qn_conf->{"must_email"} ||= 0
$qn_conf->{"must_email"}
Truth table0%0/2
A
A= $qn_conf->{"must_email"}
Aresult
11
00
50 0 ▶ $qn_conf->{must_message} ||= 1;
Condition0%0/2
$qn_conf->{"must_message"} ||= 1
l!l
00
MC/DC0%0/1
$qn_conf->{"must_message"} ||= 1
$qn_conf->{"must_message"}
Truth table0%0/2
A
A= $qn_conf->{"must_message"}
Aresult
11
00
51 0 ▶ $qn_conf->{on_success} ||= 'quicknote_success';
Condition0%0/2
$qn_conf->{"on_success"} ||= "quicknote_success"
l!l
00
MC/DC0%0/1
$qn_conf->{"on_success"} ||= "quicknote_success"
$qn_conf->{"on_success"}
Truth table0%0/2
A
A= $qn_conf->{"on_success"}
Aresult
11
00
52 $qn_conf->{success} = 'Your message has been successfuly sent'
53 0 ▶ unless defined $qn_conf->{success};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $qn_conf->{"success"} 0 0 0
54  
55 0 for ( qw/quicknote_name quicknote_email quicknote_message/ ) {
56 $query->{ $_ } = ''
57 0 ▶ unless defined $query->{ $_ };
Branch: 1 branch
BranchTrueFalseTotal
unless defined $query->{$_} 0 0 0
58 }
59  
60 0 ▶ if ( $qn_conf->{must_name} and not length $query->{quicknote_name} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($qn_conf->{"must_name"} and not length $query->{"quicknote_name"}) 0 0 0
Condition0%0/3
$qn_conf->{"must_name"} and not length $query->{"quicknote_name"}
!ll&&!rl&&r
000
MC/DC0%0/2
$qn_conf->{"must_name"} and not length $query->{"quicknote_name"}
$qn_conf->{"must_name"} not length $query->{"quicknote_name"}
Truth table0%0/3
A and not(B)
A= $qn_conf->{"must_name"}B= not length $query->{"quicknote_name"}
ABresult
0X0
100
111
61 0 $template->param( error => 'Missing parameter <em>Name</em>' );
62 0 return;
63 }
64  
65 0 ▶ if ( $qn_conf->{must_email} and not length $query->{quicknote_email} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($qn_conf->{"must_email"} and not length $query->{"quicknote_email"}) 0 0 0
Condition0%0/3
$qn_conf->{"must_email"} and not length $query->{"quicknote_email"}
!ll&&!rl&&r
000
MC/DC0%0/2
$qn_conf->{"must_email"} and not length $query->{"quicknote_email"}
$qn_conf->{"must_email"} not length $query->{"quicknote_email"}
Truth table0%0/3
A and not(B)
A= $qn_conf->{"must_email"}B= not length $query->{"quicknote_email"}
ABresult
0X0
100
111
66 0 $template->param( error => 'Missing parameter <em>E-mail</em>' );
67 0 return;
68 }
69  
70 0 ▶ if ( $qn_conf->{must_message}
Branch: 1 branch
BranchTrueFalseTotal
if ($qn_conf->{"must_message"} and not length $query->{"quicknote_message"}) 0 0 0
Condition0%0/3
$qn_conf->{"must_message"} and not length $query->{"quicknote_message"}
!ll&&!rl&&r
000
MC/DC0%0/2
$qn_conf->{"must_message"} and not length $query->{"quicknote_message"}
$qn_conf->{"must_message"} not length $query->{"quicknote_message"}
Truth table0%0/3
A and not(B)
A= $qn_conf->{"must_message"}B= not length $query->{"quicknote_message"}
ABresult
0X0
100
111
71 and not length $query->{quicknote_message}
72 ) {
73 0 $template->param( error => 'Missing parameter <em>Message</em>' );
74 0 return;
75 }
76  
77 0 ▶ if ( length( $query->{quicknote_name} ) > $qn_conf->{name_max} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $query->{"quicknote_name"} > $qn_conf->{"name_max"}) 0 0 0
78 $template->param(
79 error => 'Parameter <em>Name</em> cannot exceed '
80 0 . $qn_conf->{name_max} . ' characters'
81 );
82 0 return;
83 }
84  
85 0 ▶ if ( length( $query->{quicknote_email} ) > $qn_conf->{email_max} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $query->{"quicknote_email"} > $qn_conf->{"email_max"}) 0 0 0
86 $template->param(
87 error => 'Parameter <em>E-mail</em> cannot exceed '
88 0 . $qn_conf->{email_max} . ' characters'
89 );
90 0 return;
91 }
92  
93 0 ▶ if ( length( $query->{quicknote_message} ) > $qn_conf->{message_max} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $query->{"quicknote_message"} > $qn_conf->{"message_max"}) 0 0 0
94 $template->param(
95 error => 'Parameter <em>Message</em> cannot exceed '
96 0 . $qn_conf->{message_max} . ' characters'
97 );
98 0 return;
99 }
100  
101 0 $self->_send_mail( $qn_conf, $query );
102 0 $template->param( success => $qn_conf->{success} );
103 0 return 1;
104 }
105  
106 0 ▶sub _send_mail {
Subroutine _send_mail: not called CC=6 SCAR=37.4
107 0 my ( $self, $qn_conf, $query ) = @_;
108  
109 0 require Mail::Send;
110 0 my $email = Mail::Send->new;
111  
112 $qn_conf->{to} = [ $qn_conf->{to} ]
113 0 ▶ unless ref $qn_conf->{to};
Branch: 1 branch
BranchTrueFalseTotal
unless ref $qn_conf->{"to"} 0 0 0
114  
115 $qn_conf->{subject} = 'Quicknote'
116 0 ▶ unless defined $qn_conf->{subject};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $qn_conf->{"subject"} 0 0 0
117  
118 0 $email->to( @{ $qn_conf->{to} } );
119 0 $email->subject( $qn_conf->{subject} );
120  
121 0 my $fh;
122 0 ▶ if ( defined $qn_conf->{mailer} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $qn_conf->{'mailer'}) { } 0 0 0
123 0 ▶ if ( $qn_conf->{mailer} eq 'testfile' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($qn_conf->{"mailer"} eq "testfile") 0 0 0
124 0 $Mail::Mailer::testfile::config{outfile} = 'mailer.testfile';
125 }
126 0 $fh = $email->open( $qn_conf->{mailer} );
127 }
128 else {
129 0 $fh = $email->open;
130 }
131  
132 0 print $fh $self->_make_email_body( $qn_conf, $query );
133  
134 0 ▶ $fh->close
Branch: 1 branch
BranchTrueFalseTotal
$fh->close or die "couldn't send whole message: $!\n" 0 0 0
135 or die "couldn't send whole message: $!\n";
136  
137 0 return 1;
138 }
139  
140 0 ▶sub _make_email_body {
Subroutine _make_email_body: not called CC=4 SCAR=30.0
141 0 my ( $self, $qn_conf, $query ) = @_;
142  
143 0 my $format = $qn_conf->{format};
144 0 ▶ unless ( defined $format ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $format) 0 0 0
145 0 $format = <<'END_FORMAT';
146 Quicknote from host {::{host}::} sent on {::{time}::}
147 Name: {::{name}::}
148 E-mail: {::{email}::}
149 Message:
150 {::{message}::}
151 END_FORMAT
152 }
153  
154 0 for ( qw/quicknote_name quicknote_email quicknote_message/ ) {
155 $query->{$_} = 'N/A'
156 0 ▶ unless length $query->{$_};
Branch: 1 branch
BranchTrueFalseTotal
unless length $query->{$_} 0 0 0
157 }
158  
159 0 my $sent_time = localtime;
160 0 $format =~ s/\{::\{time}::}/$sent_time/g;
161 0 $format =~ s/\{::\{host}::}/$qn_conf->{sender_host}/g;
162 0 $format =~ s/\{::\{name}::}/$query->{quicknote_name}/g;
163 0 $format =~ s/\{::\{email}::}/$query->{quicknote_email}/g;
164 0 $format =~ s/\{::\{message}::}/$query->{quicknote_message}/g;
165  
166 0 return $format;
167 }
168  
169 0 ▶sub _setup_form {
Subroutine _setup_form: not called CC=1 SCAR=6.9
170 0 my ( $self, $query ) = @_;
171 0 my $template
172 = HTML::Template->new_scalar_ref( \ $self->_form_template );
173  
174 $template->param(
175 page => $query->{page},
176 name => $query->{quicknote_name},
177 email => $query->{quicknote_email},
178 message => $query->{quicknote_message},
179 0 );
180  
181 0 return $template;
182 }
183  
184 0 ▶sub _form_template {
Subroutine _form_template: not called CC=1 SCAR=6.9
185 0 return <<'END_FORM';
186 <tmpl_if name="success">
187 <p class="quicknote_success"><tmpl_var name="success"></p>
188 <tmpl_else>
189 <form class="quicknote" action="<tmpl_var escape="html" name="action">" method="POST">
190 <div>
191 <tmpl_if name="error">
192 <p class="quicknote_error"><tmpl_var name="error"></p>
193 </tmpl_if>
194 <input type="hidden" name="quicknote_username" value="your full name">
195 <input type="hidden" name="page" value="<tmpl_var name="page">">
196 <ul>
197 <li>
198 <label for="quicknote_name">Name:</label
199 ><input type="text" name="quicknote_name" id="quicknote_name"
200 value="<tmpl_var escape="html" name="name">">
201 </li>
202 <li>
203 <label for="quicknote_email">E-mail: </label
204 ><input type="text" name="quicknote_email" id="quicknote_email"
205 value="<tmpl_var escape="html" name="email">">
206 </li>
207 <li>
208 <label for="quicknote_message">Message: </label
209 ><textarea name="quicknote_message" id="quicknote_message"
210 cols="40" rows="10"><tmpl_var escape="html" name="message"></textarea>
211 </li>
212 </ul>
213 <input type="submit" id="quicknote_submit" value="Send">
214 </div>
215 </form>
216 </tmpl_if>
217 END_FORM
218 }
219  
220  
221 1 1;
222 __END__
« ZofCMS/Plugin/DBI.pm ↑ Summary ZofCMS/Plugin/FileList.pm »