ZofCMS/Plugin/FeatureSuggestionBox.pm

filter: Statementstmt 26.6% 20 / 75 Branchbran 0.0% 0 / 34 Conditioncond 0.0% 0 / 19 MC/DCmcdc 0.0% 0 / 12 Subroutinesub 33.3% 6 / 18 Podpod n/a totaltotal 16.4% 26 / 158 CC 26 SCAR 40.5
CC
26
Cov
16%
_check_suggestion
132.0
_do
72.0
_send_suggestion
56.0
CRAP 57.6
« ZofCMS/Plugin/FileTypeIcon.pm ↑ Summary ZofCMS/Plugin/StartPage.pm »
1 package App::ZofCMS::Plugin::FeatureSuggestionBox;
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 ▶use HTML::Template;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use HTML::Entities;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use MIME::Lite;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 0 ▶sub _key { 'plug_feature_suggestion_box' }
Subroutine _key: not called CC=1 SCAR=6.9
14 0 ▶sub _defaults {
Subroutine _defaults: not called CC=1 SCAR=6.9
15 return (
16 # from => undef,
17 # email_template => email_template(),
18 # to => undef,
19 0 ▶ user_name => sub { $_[0]->{d}{user}{name} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
20 0 ▶ user_email => sub { $_[0]->{d}{user}{email} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
21 0 subject => 'Feature Suggestion',
22 no_identification => 1,
23 submit_button => q|<input type="submit" class="submit_button"|
24 . q| value="Send">|,
25 # mime_lite_params => [
26 # 'smtp',
27 # 'foosmail',
28 # Auth => [ 'foos/bars', 'p4ss' ],
29 # ],
30 );
31 }
32 0 ▶sub _do {
Subroutine _do: not called CC=8 SCAR=42.8
33 0 my ( $self, $conf, $t, $q, $config ) = @_;
34  
35 0 for ( qw/to user_name user_email/ ) {
36 $conf->{$_} = $conf->{$_}->( $t, $q, $config )
37 0 ▶ if ref $conf->{$_} eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $conf->{$_} eq "CODE" 0 0 0
38 }
39  
40 return
41 0 ▶ unless $conf->{to};
Branch: 1 branch
BranchTrueFalseTotal
unless $conf->{"to"} 0 0 0
42  
43 0 ▶ $self->{Q_PAGE} = ( $q->{dir} || '' ) . ( $q->{page} || '' );
Condition0%0/4
$q->{'dir'} || ''
l!l
00
$q->{'page'} || ''
l!l
00
MC/DC0%0/1
$q->{'dir'} || ''
$q->{'dir'}
MC/DC0%0/1
$q->{'page'} || ''
$q->{'page'}
Truth table0%0/2
A
A= $q->{'dir'}
Aresult
11
00
Truth table0%0/2
A
A= $q->{'page'}
Aresult
11
00
44 0 $self->{CONF} = $conf;
45 0 $self->{Q} = $q;
46 0 $self->{T} = $t;
47  
48 0 ▶ if ( $q->{plugfsb_send} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($q->{"plugfsb_send"}) 0 0 0
49 0 ▶ $self->_check_suggestion
Branch: 1 branch
BranchTrueFalseTotal
$self->_check_suggestion and $self->_send_suggestion 0 0 0
50 and $self->_send_suggestion;
51 }
52  
53 0 $t->{t}{plug_feature_suggestion_box_form} = $self->_make_form;
54 }
55  
56 0 ▶sub _send_suggestion {
Subroutine _send_suggestion: not called CC=7 SCAR=40.3
57 0 my $self = shift;
58 0 my $q = $self->{Q};
59 0 my $conf = $self->{CONF};
60  
61 my $template = HTML::Template->new(
62 die_on_bad_params => 0,
63 ref $conf->{email_template}
64 0 ▶ ? ( filename => ${ $conf->{email_template} } )
Branch: 1 branch
BranchTrueFalseTotal
_has_value($conf->{'email_template'}) ? : 0 0 0
65 : _has_value( $conf->{email_template} )
66 ? ( scalarref => \ $conf->{email_template} )
67 0 ▶ : ( scalarref => \ _email_template() )
Branch: 1 branch
BranchTrueFalseTotal
ref $conf->{'email_template'} ? : 0 0 0
68 );
69  
70 0 my $suggestion = encode_entities $q->{plugfsb_suggestion};
71 0 $suggestion =~ s/\r?\n/<br>/g;
72  
73 my $name = _has_value( $conf->{user_name} )
74 0 ▶ ? $conf->{user_name} : $q->{plugfsb_name};
Branch: 1 branch
BranchTrueFalseTotal
_has_value($conf->{'user_name'}) ? : 0 0 0
75  
76 my $email = _has_value( $conf->{user_email} )
77 0 ▶ ? $conf->{user_email} : $q->{plugfsb_email};
Branch: 1 branch
BranchTrueFalseTotal
_has_value($conf->{'user_email'}) ? : 0 0 0
78  
79 0 $template->param(
80 name => $name,
81 email => $email,
82 suggestion => $suggestion,
83 has_name => _has_value( $name ),
84 has_email => _has_value( $email ),
85 );
86  
87 my $msg = MIME::Lite->new (
88 Subject => $conf->{subject},
89 ( defined $conf->{from} ? ( From => $conf->{from} ) : (), ),
90 To => $conf->{to},
91 0 ▶ Type => 'text/html',
Branch: 1 branch
BranchTrueFalseTotal
defined $conf->{'from'} ? : 0 0 0
92 Data => $template->output,
93 );
94  
95 0 MIME::Lite->send( @{ $conf->{mime_lite_params} } )
96 0 ▶ if $conf->{mime_lite_params};
Branch: 1 branch
BranchTrueFalseTotal
if $conf->{"mime_lite_params"} 0 0 0
97  
98 0 $msg->send;
99  
100 0 $self->{SEND_SUCCESS} = 1;
101 0 $self->{T}{t}{plug_feature_suggestion_box_sent} = 1;
102 }
103  
104 0 ▶sub _check_suggestion {
Subroutine _check_suggestion: not called CC=11 SCAR=48.8
105 0 my $self = shift;
106 0 my $q = $self->{Q};
107 0 my $conf = $self->{CONF};
108  
109 return $self->_set_error('You must fill in your name')
110 if not $conf->{no_identification}
111 0 ▶ and not _has_value( $q->{plugfsb_name} );
Branch: 1 branch
BranchTrueFalseTotal
unless $conf->{"no_identification"} or _has_value($q->{"plugfsb_name"}) 0 0 0
Condition0%0/3
$conf->{"no_identification"} or _has_value($q->{"plugfsb_name"})
l!l&&r!l&&!r
000
MC/DC0%0/2
$conf->{"no_identification"} or _has_value($q->{"plugfsb_name"})
$conf->{"no_identification"} _has_value($q->{"plugfsb_name"})
Truth table0%0/3
A or B
A= $conf->{"no_identification"}B= _has_value($q->{"plugfsb_name"})
ABresult
1X1
011
000
112  
113 return $self->_set_error('"Your name" cannot be longer than 200 characters')
114 if not $conf->{no_identification}
115 0 ▶ and length( $q->{plugfsb_name} ) > 200;
Branch: 1 branch
BranchTrueFalseTotal
if not $conf->{"no_identification"} and length $q->{"plugfsb_name"} > 200 0 0 0
Condition0%0/3
not $conf->{"no_identification"} and length $q->{"plugfsb_name"} > 200
!ll&&!rl&&r
000
MC/DC0%0/2
not $conf->{"no_identification"} and length $q->{"plugfsb_name"} > 200
not $conf->{"no_identification"} length $q->{"plugfsb_name"} > 200
Truth table0%0/3
not(A) and B
A= not $conf->{"no_identification"}B= length $q->{"plugfsb_name"} > 200
ABresult
0X0
100
111
116  
117 return $self->_set_error('You must fill in your email address')
118 if not $conf->{no_identification}
119 0 ▶ and not _has_value( $q->{plugfsb_email} );
Branch: 1 branch
BranchTrueFalseTotal
unless $conf->{"no_identification"} or _has_value($q->{"plugfsb_email"}) 0 0 0
Condition0%0/3
$conf->{"no_identification"} or _has_value($q->{"plugfsb_email"})
l!l&&r!l&&!r
000
MC/DC0%0/2
$conf->{"no_identification"} or _has_value($q->{"plugfsb_email"})
$conf->{"no_identification"} _has_value($q->{"plugfsb_email"})
Truth table0%0/3
A or B
A= $conf->{"no_identification"}B= _has_value($q->{"plugfsb_email"})
ABresult
1X1
011
000
120  
121 return $self->_set_error('"Your email" cannot be longer than 300 characters')
122 if not $conf->{no_identification}
123 0 ▶ and length( $q->{plugfsb_email} ) > 300;
Branch: 1 branch
BranchTrueFalseTotal
if not $conf->{"no_identification"} and length $q->{"plugfsb_email"} > 300 0 0 0
Condition0%0/3
not $conf->{"no_identification"} and length $q->{"plugfsb_email"} > 300
!ll&&!rl&&r
000
MC/DC0%0/2
not $conf->{"no_identification"} and length $q->{"plugfsb_email"} > 300
not $conf->{"no_identification"} length $q->{"plugfsb_email"} > 300
Truth table0%0/3
not(A) and B
A= not $conf->{"no_identification"}B= length $q->{"plugfsb_email"} > 300
ABresult
0X0
100
111
124  
125 return $self->_set_error('You must fill in your suggestion')
126 0 ▶ if not _has_value( $q->{plugfsb_suggestion} );
Branch: 1 branch
BranchTrueFalseTotal
unless _has_value($q->{"plugfsb_suggestion"}) 0 0 0
127  
128 return $self->_set_error('"Your suggestion" cannot be longer than 300,000 characters')
129 0 ▶ if length( $q->{plugfsb_suggestion} ) > 300000;
Branch: 1 branch
BranchTrueFalseTotal
if length $q->{"plugfsb_suggestion"} > 300000 0 0 0
130  
131 0 return 1;
132 }
133  
134 0 ▶sub _make_form {
Subroutine _make_form: not called CC=1 SCAR=6.9
135 0 my $self = shift;
136 0 my $conf = $self->{CONF};
137 0 my $q = $self->{Q};
138  
139 0 my $template = HTML::Template->new_scalar_ref(
140 \ $self->_get_form_html_template,
141 die_on_bad_params => 0,
142 );
143  
144 $template->param(
145 page => $self->{Q_PAGE},
146 error => $self->{ERROR},
147 send_success => $self->{SEND_SUCCESS},
148 (
149 map +( $_ => $q->{"plugfsb_$_"} ),
150 qw/name email suggestion/,
151 ),
152 (
153 0 map +( $_ => $conf->{$_} ),
154 qw/submit_button no_identification/,
155 ),
156 );
157  
158 0 return $template->output;
159 }
160  
161 0 ▶sub _set_error {
Subroutine _set_error: not called CC=1 SCAR=6.9
162 0 my $self = shift;
163 0 $self->{ERROR} = shift;
164 0 return;
165 }
166  
167 0 ▶sub _has_value {
Subroutine _has_value: not called CC=3 SCAR=24.8
168 0 my $v = shift;
169 0 ▶ return 1
Branch: 1 branch
BranchTrueFalseTotal
if defined $v and length $v 0 0 0
Condition0%0/3
defined $v and length $v
!ll&&!rl&&r
000
MC/DC0%0/2
defined $v and length $v
defined $v length $v
Truth table0%0/3
A and B
A= defined $vB= length $v
ABresult
0X0
100
111
170 if defined $v and length $v;
171  
172 0 return 0;
173 }
174  
175 0 ▶sub _email_template {
Subroutine _email_template: not called CC=1 SCAR=6.9
176 0 return <<'END_HTML';
177 <h1>Feature Suggestion</h1>
178  
179 <dl>
180 <tmpl_if name='has_name'>
181 <dt>From:</dt>
182 <dd><tmpl_var escape='html' name='name'></dd>
183 </tmpl_if>
184  
185 <tmpl_if name='has_email'>
186 <dt>Email:</dt>
187 <dd><a href="mailto:<tmpl_var escape='html' name='email'>"><tmpl_var escape='html' name='email'></a></dd>
188 </tmpl_if>
189  
190 <dt>Suggestion:</dt>
191 <dd><tmpl_var name='suggestion'></dd>
192 </dl>
193 END_HTML
194 }
195  
196 0 ▶sub _get_form_html_template {
Subroutine _get_form_html_template: not called CC=1 SCAR=6.9
197 0 return <<'END_HTML';
198 <tmpl_if name="send_success">
199 <p class="success-message">Successfully sent.</p>
200 <tmpl_else>
201 <form action="" method="POST" id="plugfsb_form">
202 <div>
203 <input type="hidden" name="page" value="<tmpl_var escape='html' name='page'>">
204 <input type="hidden" name="plugfsb_send" value="1">
205  
206 <tmpl_if name="error">
207 <p class="error"><tmpl_var escape='html' name='error'></p>
208 </tmpl_if>
209  
210 <ul>
211 <tmpl_unless name="no_identification">
212 <li><label for="plugfsb_name">Your name:</label
213 ><input type="text" class="input_text"
214 name="plugfsb_name" id="plugfsb_name"
215 value="<tmpl_var escape='html' name='name'>"></li>
216 <li><label for="plugfsb_email">Your email:</label
217 ><input type="text" class="input_text"
218 name="plugfsb_email" id="plugfsb_email"
219 value="<tmpl_var escape='html' name='email'>"></li>
220 </tmpl_unless>
221 <li><label for="plugfsb_suggestion" class="textarea_label">Your suggestion:</label
222 ><textarea id="plugfsb_suggestion" cols="60" rows="5"
223 name="plugfsb_suggestion"
224 ><tmpl_var escape='html' name='suggestion'></textarea></li>
225 </ul>
226  
227 <tmpl_var name='submit_button'>
228 </div>
229 </form>
230 </tmpl_if>
231 END_HTML
232 }
233  
234 1 1;
235 __END__
« ZofCMS/Plugin/FileTypeIcon.pm ↑ Summary ZofCMS/Plugin/StartPage.pm »