blib/lib/HTML/EP.pm

filter: Statementstmt 65.4% 398 / 608 Branchbran 53.8% 197 / 366 Conditioncond 24.8% 38 / 153 MC/DCmcdc 11.2% 10 / 89 Subroutinesub 68.5% 37 / 54 Podpod 0.0% 0 / 26 totaltotal 52.4% 680 / 1296 CC 246 SCAR 35.8
CC
246
Cov
56%
_ep_debug
156.0
SqlSetupResult
156.0
_ep_input_sql_query
110.0
CRAP 35.8
« blib/lib/HTML/EP/Session.pm ↑ Summary blib/lib/HTML/EP/Session/Dumper.pm »
1 # -*- perl -*-
2 #
3 # HTML::EP - A Perl based HTML extension.
4 #
5 #
6 # Copyright (C) 1998 Jochen Wiedmann
7 # Am Eisteich 9
8 # 72555 Metzingen
9 # Germany
10 #
11 # Email: joe@ispsoft.de
12 #
13 #
14 # Portions Copyright (C) 1999 OnTV Pittsburgh, L.P.
15 # 123 University St.
16 # Pittsburgh, PA 15213
17 # USA
18 #
19 # Phone: 1 412 681 5230
20 # Developer: Jason McMullan <jmcc@ontv.com>
21 # Developer: Erin Glendenning <erg@ontv.com>
22 #
23 #
24 # All rights reserved.
25 #
26 # You may distribute this module under the terms of either
27 # the GNU General Public License or the Artistic License, as
28 # specified in the Perl README file.
29 #
30 ############################################################################
31  
32 10 require 5.005;
33 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35 10 ▶use CGI ();
Subroutine BEGIN: called CC=1 SCAR=0.0
36 10 ▶use Symbol ();
Subroutine BEGIN: called CC=1 SCAR=0.0
37 10 ▶use HTML::EP::Config ();
Subroutine BEGIN: called CC=1 SCAR=0.0
38 10 ▶use HTML::EP::Parser ();
Subroutine BEGIN: called CC=1 SCAR=0.0
39  
40  
41 package HTML::EP;
42  
43 10 $HTML::EP::VERSION = '0.2011';
44  
45  
46 88 ▶sub new {
Subroutine new: called CC=7 SCAR=21.8
Pod undocumented
47 88 my $proto = shift;
48 88 ▶ my $self = (@_ == 1) ? {%{shift()}} : { @_ };
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 9 79 88
49 88 $self->{'_ep_output'} = '';
50 88 $self->{'_ep_output_stack'} = [];
51 88 ▶ $self->{'_ep_config'} ||= $HTML::EP::Config::CONFIGURATION;
Condition33%1/3
$self->{"_ep_config"} ||= $HTML::EP::Config::CONFIGURATION
l!l&&r!l&&!r
0880
MC/DC0%0/2
$self->{"_ep_config"} ||= $HTML::EP::Config::CONFIGURATION
$self->{"_ep_config"} $HTML::EP::Config::CONFIGURATION
Truth table33%1/3
A ||= B
A= $self->{"_ep_config"}B= $HTML::EP::Config::CONFIGURATION
ABresult
1X1
011
000
52 88 ▶ $self->{'debug'} ||= 0;
Condition50%1/2
$self->{"debug"} ||= 0
l!l
088
MC/DC0%0/1
$self->{"debug"} ||= 0
$self->{"debug"}
Truth table50%1/2
A
A= $self->{"debug"}
Aresult
11
00
53 88 ▶ $self->{'cgi'} ||= (CGI->new() || die "Failed to create CGI object: $!");
Condition40%2/5
$self->{"cgi"} ||= "CGI"->new || die("Failed to create CGI object: $!")
l!l&&r!l&&!r
0880
'CGI'->new || die("Failed to create CGI object: $!")
l!l
880
MC/DC0%0/2
$self->{"cgi"} ||= "CGI"->new || die("Failed to create CGI object: $!")
$self->{"cgi"} 'CGI'->new
Truth table33%1/3
A ||= B
A= $self->{"cgi"}B= 'CGI'->new
ABresult
1X1
011
000
54 88 ▶ bless($self, (ref($proto) || $proto));
Condition33%1/3
ref $proto || $proto
l!l&&r!l&&!r
0880
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
55 }
56  
57 86 ▶sub Run {
Subroutine Run: called CC=6 SCAR=18.4
Pod undocumented
58 86 my($self, $template) = @_;
59 86 my $parser = HTML::EP::Parser->new();
60 86 my $r = $self->{'_ep_r'};
61 86 ▶ $self->{'env'} ||= $r ?
Branch: 1 branch
BranchTrueFalseTotal
$r ? : 0 86 86
Condition33%1/3
$self->{"env"} ||= $r ? {$r->cgi_env, "PATH_INFO", $r->uri} : \%ENV
l!l&&r!l&&!r
0860
MC/DC0%0/2
$self->{"env"} ||= $r ? {$r->cgi_env, "PATH_INFO", $r->uri} : \%ENV
$self->{"env"} $r ? {$r->cgi_env, "PATH_INFO", $r->uri} : \%ENV
Truth table33%1/3
A ||= B
A= $self->{"env"}B= $r ? {$r->cgi_env, "PATH_INFO", $r->uri} : \%ENV
ABresult
1X1
011
000
62 { $r->cgi_env(), 'PATH_INFO' => $r->uri() } : \%ENV;
63 86 ▶ if ($template) {
Branch: 1 branch
BranchTrueFalseTotal
if ($template) { } 84 2 86
64 84 $parser->parse($template);
65 } else {
66 2 ▶ my $file = $self->{'env'}->{'PATH_TRANSLATED'}
Condition50%1/2
$self->{'env'}{'PATH_TRANSLATED'} || die('Missing server environment (PATH_TRANSLATED variable)')
l!l
20
MC/DC0%0/1
$self->{'env'}{'PATH_TRANSLATED'} || die('Missing server environment (PATH_TRANSLATED variable)')
$self->{'env'}{'PATH_TRANSLATED'}
Truth table50%1/2
A
A= $self->{'env'}{'PATH_TRANSLATED'}
Aresult
11
00
67 || die "Missing server environment (PATH_TRANSLATED variable)";
68 2 my $fh = Symbol::gensym();
69 2 ▶ open($fh, "<$file") || die "Failed to open $file: $!";
Branch: 1 branch
BranchTrueFalseTotal
open $fh, "<$file" or die "Failed to open ${file}: $!" 2 0 2
70 2 $parser->parse_file($fh);
71 }
72 86 $parser->eof();
73 86 my $tokens = HTML::EP::Tokens->new('tokens' => $parser->{'_ep_tokens'});
74 86 $self->{'_ep_output'} = $self->ParseVars($self->TokenMarch($tokens));
75 }
76  
77  
78 2 ▶sub CgiRun {
Subroutine CgiRun: called CC=16 SCAR=42.2
Pod undocumented
79 2 my($self, $path, $r) = @_;
80 2 my $cgi = $self->{'cgi'};
81 2 my $ok_templates = $self->{'_ep_config'}->{'ok_templates'};
82 2 local $| = 1;
83 2 my $output = eval {
84 die "Access to $path forbidden; check ok_templates in ",
85 2 ▶ $INC{'HTML/EP/Config.pm'}
Branch: 1 branch
BranchTrueFalseTotal
if $ok_templates and not $path =~ /$ok_templates/ 0 2 2
Condition33%1/3
$ok_templates and not $path =~ /$ok_templates/
!ll&&!rl&&r
020
MC/DC0%0/2
$ok_templates and not $path =~ /$ok_templates/
$ok_templates not $path =~ /$ok_templates/
Truth table33%1/3
A and not(B)
A= $ok_templatesB= not $path =~ /$ok_templates/
ABresult
0X0
100
111
86 if $ok_templates && $path !~ /$ok_templates/;
87 2 ▶ $self->_ep_debug({}) if $cgi->param('debug');
Branch: 1 branch
BranchTrueFalseTotal
if $cgi->param("debug") 0 2 2
88 2 $self->Run();
89 };
90  
91 2 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 2 0 2
92 2 ▶ if ($@ =~ /_ep_exit, ignore/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@ =~ /_ep_exit, ignore/) { } 0 2 2
93 0 $output .= $self->ParseVars($self->{'_ep_output'});
94 } else {
95 2 my $errmsg;
96 2 my $errstr = $@;
97 my $errfile = $self->{_ep_err_type} ?
98 2 ▶ $self->{_ep_err_file_user} : $self->{_ep_err_file_system};
Branch: 1 branch
BranchTrueFalseTotal
$self->{'_ep_err_type'} ? : 0 2 2
99 2 ▶ if ($errfile) {
Branch: 1 branch
BranchTrueFalseTotal
if ($errfile) 0 2 2
100 0 ▶ if ($errfile =~ /^\//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($errfile =~ m[^/]) 0 0 0
101 my $derrfile = $r ?
102 0 ▶ $r->cgi_var('DOCUMENT_ROOT') : $ENV{'DOCUMENT_ROOT'}
Branch: 1 branch
BranchTrueFalseTotal
$r ? : 0 0 0
103 . $errfile;
104 0 ▶ if ($self->{'debug'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"debug"}) 0 0 0
105 $self->print("Error type = " . $self->{_ep_err_type} .
106 0 ", error file = $errfile" .
107 ", derror file = $derrfile\n");
108 }
109 0 ▶ if (-f $derrfile) { $errfile = $derrfile }
Branch: 1 branch
BranchTrueFalseTotal
if (-f $derrfile) 0 0 0
110 }
111 0 my $fh = Symbol::gensym();
112 0 ▶ if (open($fh, "<$errfile")) {
Branch: 1 branch
BranchTrueFalseTotal
if (open $fh, "<$errfile") 0 0 0
113 0 local $/ = undef;
114 0 $errmsg = <$fh>;
115 0 close($fh);
116 }
117 }
118 2 ▶ if (!$errmsg) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($errmsg) 2 0 2
119 $errmsg = $self->{_ep_err_type} ?
120 2 ▶ $self->{_ep_err_msg_user} : $self->{_ep_err_msg_system};
Branch: 1 branch
BranchTrueFalseTotal
$self->{'_ep_err_type'} ? : 0 2 2
121 }
122 2 return $self->SimpleError($errmsg, $errstr);
123 }
124 }
125  
126 0 ▶ if (!$self->{_ep_stop}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{"_ep_stop"}) 0 0 0
127 $self->print($cgi->header($self->SetCookies(),
128 0 %{$self->{'_ep_headers'}}), $output);
129 }
130 }
131  
132 32 ▶sub FindEndTag {
Subroutine FindEndTag: called CC=7 SCAR=19.5
Pod undocumented
133 32 my($self, $tokens, $tag) = @_;
134 32 my $level = 0;
135 32 ▶ while (defined(my $token = $tokens->Token())) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $token = $tokens->Token)) 83 0 83
136 83 ▶ if ($token->{'type'} eq 'S') {
Branch: 2 branches
BranchTrueFalseTotal
if ($token->{'type'} eq 'S') { } 9 74 83
elsif ($token->{'type'} eq 'E') { } 39 35 74
137 9 ▶ ++$level if $token->{'tag'} eq $tag;
Branch: 1 branch
BranchTrueFalseTotal
if $token->{"tag"} eq $tag 5 4 9
138 } elsif ($token->{'type'} eq 'E') {
139 39 ▶ if ($token->{'tag'} eq $tag) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token->{"tag"} eq $tag) 37 2 39
140 37 ▶ return $tokens->First() unless $level--;
Branch: 1 branch
BranchTrueFalseTotal
unless $level-- 32 5 37
141 }
142 }
143 }
144 0 die "$tag without /$tag";
145 }
146  
147 15 ▶sub AttrVal {
Subroutine AttrVal: called CC=4 SCAR=13.9
Pod undocumented
148 15 my($self, $val, $tokens, $token, $parse) = @_;
149 15 ▶ return $val if defined($val);
Branch: 1 branch
BranchTrueFalseTotal
if defined $val 3 12 15
150 12 my $first = $tokens->First();
151 my $last = $self->FindEndTag($tokens,
152 12 ▶ ref($token) ? $token->{'tag'} : $token);
Branch: 1 branch
BranchTrueFalseTotal
ref $token ? : 12 0 12
153 12 my $output = $self->TokenMarch($tokens->Clone($first, $last-1));
154 12 ▶ $parse ? $self->ParseVars($output) : $output;
Branch: 1 branch
BranchTrueFalseTotal
$parse ? : 9 3 12
155 }
156  
157 155 ▶sub ParseAttr {
Subroutine ParseAttr: called CC=5 SCAR=16.1
Pod undocumented
158 155 my $self = shift; my $attr = shift;
159 155 my $parsed_attr = {};
160 155 ▶ while (my($var, $val) = each %$attr) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$attr) 187 155 342
161 187 ▶ if ($val =~ /\$\_\W/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($val =~ /\$\_\W/) { } 49 138 187
elsif ($val =~ /\$/) { } 34 104 138
162 49 $_ = $self;
163 49 $parsed_attr->{$var} = eval $val;
164 49 ▶ die $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 49 49
165 } elsif ($val =~ /\$/) {
166 34 $parsed_attr->{$var} = $self->ParseVars($val);
167 } else {
168 104 $parsed_attr->{$var} = $val;
169 }
170 }
171 155 $parsed_attr;
172 }
173  
174 75 ▶sub RepeatedTokenMarch {
Subroutine RepeatedTokenMarch: called CC=1 SCAR=0.0
Pod undocumented
175 75 my $self = shift; my $tokens = shift;
176 75 my $first = $tokens->First();
177 75 my $last = $tokens->Last();
178 75 my $res = $self->TokenMarch($tokens);
179 75 $tokens->First($first);
180 75 $tokens->Last($last);
181 75 $res;
182 }
183 232 ▶sub TokenMarch {
Subroutine TokenMarch: called CC=9 SCAR=24.1
Pod undocumented
184 232 my($self, $tokens) = @_;
185 232 my $debug = $self->{'debug'};
186  
187 232 push(@{$self->{'_ep_output_stack'}}, $self->{'_ep_output'});
188 232 $self->{'_ep_output'} = '';
189 232 ▶ $self->print("TokenMarch: From ", $tokens->First(), " to ",
Branch: 1 branch
BranchTrueFalseTotal
if $debug >= 2 0 232 232
190 $tokens->Last(), ".\n") if $debug >= 2;
191 232 ▶ while (defined(my $token = $tokens->Token())) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $token = $tokens->Token)) 345 224 569
192 345 my $type = $token->{'type'};
193 345 my $res;
194 345 ▶ if ($type eq 'T') {
Branch: 4 branches
BranchTrueFalseTotal
if ($type eq 'T') { } 210 135 345
elsif ($token->{'type'} eq 'S') { } 129 6 135
elsif ($token->{'type'} eq 'I') { } 6 0 6
elsif ($token->{'type'} eq 'E') { } 0 0 0
195 210 $res = $token->{'text'};
196 } elsif ($token->{'type'} eq 'S') {
197 129 my $method = "_$token->{'tag'}";
198 129 my $attr = $token->{'attr'};
199 129 $method =~ s/\-/_/g;
200 129 $res = $self->$method($self->ParseAttr($attr), $tokens, $token);
201 121 ▶ if (!defined($res)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $res) 0 121 121
202 # Upwards compatibility: If the method returned undef, then
203 # it is a multiline tag in the sense of EP1. We've got to
204 # collect all lines until a matching /$tag and evaluate it.
205 0 my $def = delete $tokens->{'default'};
206 0 my $first = $tokens->First();
207 0 my $last = $self->FindEndTag($tokens, $token->{'tag'});
208 0 my $t = $tokens->Clone($first, $last-1);
209 0 $attr->{$def} = $self->TokenMarch($t);
210 0 $res = $self->$method($attr, $tokens);
211 }
212 } elsif ($token->{'type'} eq 'I') {
213 6 $res = $self->RepeatedTokenMarch($token->{'tokens'});
214 } elsif ($token->{'type'} eq 'E') {
215 0 die "Unexpected end tag: /$token->{'tag'} without $token->{'tag'}";
216 } else {
217 0 die "Unknown token type $self->{'type'}";
218 }
219 337 $self->{'_ep_output'} .= $res;
220 }
221 224 my $result = $self->{'_ep_output'};
222 224 ▶ $self->print("TokenMarch: Returning $result.\n") if $debug >= 2;
Branch: 1 branch
BranchTrueFalseTotal
if $debug >= 2 0 224 224
223 224 $self->{'_ep_output'} = pop(@{$self->{'_ep_output_stack'}});
224 224 $result;
225 }
226  
227  
228  
229  
230 0 ▶sub WarnHandler {
Subroutine WarnHandler: not called CC=3 SCAR=24.8
Pod undocumented
231 0 my $msg = shift;
232 0 ▶ die $msg unless defined($^S);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $^S 0 0 0
233 0 print STDERR $msg;
234 0 ▶ print STDERR "\n" unless $msg =~ /\n$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $msg =~ /\n$/ 0 0 0
235 }
236  
237  
238 2 ▶sub SimpleError {
Subroutine SimpleError: called CC=8 SCAR=22.9
Pod undocumented
239 2 my($self, $template, $errmsg, $admin) = @_;
240 2 my $r;
241 2 ▶ $r = $self->{'_ep_r'} if $self && ref($self);
Branch: 1 branch
BranchTrueFalseTotal
if $self and ref $self 2 0 2
Condition33%1/3
$self and ref $self
!ll&&!rl&&r
002
MC/DC0%0/2
$self and ref $self
$self ref $self
Truth table33%1/3
A and B
A= $selfB= ref $self
ABresult
0X0
100
111
242 2 ▶ $admin ||= ($r ? $r->cgi_var('SERVER_ADMIN') : $ENV{'SERVER_ADMIN'});
Branch: 1 branch
BranchTrueFalseTotal
$r ? : 0 2 2
Condition33%1/3
$admin ||= $r ? $r->cgi_var("SERVER_ADMIN") : $ENV{"SERVER_ADMIN"}
l!l&&r!l&&!r
020
MC/DC0%0/2
$admin ||= $r ? $r->cgi_var("SERVER_ADMIN") : $ENV{"SERVER_ADMIN"}
$admin $r ? $r->cgi_var("SERVER_ADMIN") : $ENV{"SERVER_ADMIN"}
Truth table33%1/3
A ||= B
A= $adminB= $r ? $r->cgi_var("SERVER_ADMIN") : $ENV{"SERVER_ADMIN"}
ABresult
1X1
011
000
243 2 ▶ $admin = $admin ? "<A HREF=\"mailto:$admin\">Webmaster</A>" : 'Webmaster';
Branch: 1 branch
BranchTrueFalseTotal
$admin ? : 2 0 2
244 2 my $vars = { errmsg => $errmsg, admin => $admin };
245  
246 2 ▶ if (!$template) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($template) 1 1 2
247 1 $template = <<'END_OF_HTML';
248 <HTML><HEAD><TITLE>Fatal internal error</TITLE></HEAD>
249 <BODY><H1>Fatal internal error</H1>
250 <P>An internal error occurred. The error message is:</P>
251 <PRE>
252 $errmsg$.
253 </PRE>
254 <P>Please contact the $admin$ and tell him URL, time and error message.</P>
255 <P>We apologize for any inconvenience, please try again later.</P>
256 <BR><BR><BR>
257 <P>Yours sincerely</P>
258 </BODY></HTML>
259 END_OF_HTML
260 }
261  
262 2 $template =~ s/\$(\w+)\$/$vars->{$1}/g;
263 2 ▶ if ($r) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r) { } 0 2 2
264 0 $r->print($self->{'cgi'}->header('-type' => 'text/html'), $template);
265 } else {
266 2 print("content-type: text/html\n\n", $template);
267 2 exit 0;
268 }
269 }
270  
271 0 ▶sub print ($;@) {
Subroutine print: not called CC=2 SCAR=17.9
Pod undocumented
272 0 my $self = shift;
273 0 ▶ $self->{_ep_r} ? $self->{_ep_r}->print(@_) : print @_;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'_ep_r'} ? : 0 0 0
274 }
275  
276 0 ▶sub printf {
Subroutine printf: not called CC=1 SCAR=6.9
Pod undocumented
277 0 my($self, $format, @args) = @_;
278 0 $self->print(sprintf($format, @args));
279 }
280  
281 192 ▶sub escapeHTML {
Subroutine escapeHTML: called CC=1 SCAR=0.0
Pod undocumented
282 192 my $self = shift; my $str = shift;
283 192 $str =~ s/&/&amp;/g;
284 192 $str =~ s/\"/&quot;/g;
285 192 $str =~ s/>/&gt;/g;
286 192 $str =~ s/</&lt;/g;
287 192 $str =~ s/\$/&#36;/g;
288 192 $str;
289 }
290  
291 208 ▶sub FindVar {
Subroutine FindVar: called CC=7 SCAR=20.3
Pod undocumented
292 208 my($self, $var, $subvar) = @_;
293 208 ▶ if ($var eq 'cgi') {
Branch: 1 branch
BranchTrueFalseTotal
if ($var eq "cgi") 0 208 208
294 0 $subvar =~ s/\-\>//;
295 0 return $self->{'cgi'}->param($subvar);
296 }
297  
298 208 $var = $self->{$var};
299 208 ▶ while ($subvar && $subvar =~ /^\-\>(\w+)(.*)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($subvar and $subvar =~ /^\-\>(\w+)(.*)/) 31 208 239
Condition66%2/3
$subvar and $subvar =~ /^\-\>(\w+)(.*)/
!ll&&!rl&&r
208031
MC/DC50%1/2
$subvar and $subvar =~ /^\-\>(\w+)(.*)/
$subvar $subvar =~ /^\-\>(\w+)(.*)/
Truth table66%2/3
A and B
A= $subvarB= $subvar =~ /^\-\>(\w+)(.*)/
ABresult
0X0
100
111
300 31 ▶ return '' unless ref $var;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $var 0 31 31
301 31 my $v = $1;
302 31 $subvar = $2;
303 31 ▶ if ($v =~ /^\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v =~ /^\d+$/) { } 4 27 31
304 4 $var = $var->[$v];
305 } else {
306 27 $var = $var->{$v};
307 }
308 }
309 208 ▶ defined $var ? $var : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $var ? : 208 0 208
310 }
311  
312 207 ▶sub ParseVar {
Subroutine ParseVar: called CC=12 SCAR=26.5
Pod undocumented
313 207 my($self, $type, $var, $subvar) = @_;
314 207 my $func;
315  
316 207 ▶ if ($type && $type eq '&') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type and $type eq "&") 9 198 207
Condition100%3/3
$type and $type eq "&"
!ll&&!rl&&r
18999
MC/DC100%2/2
$type and $type eq "&"
$type $type eq "&"
Truth table100%3/3
A and B
A= $typeB= $type eq "&"
ABresult
0X0
100
111
317 # Custom format
318 $func = exists($self->{'_ep_custom_formats'}->{$var}) ?
319 9 ▶ $self->{'_ep_custom_formats'}->{$var} : "_format_$var";
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{'_ep_custom_formats'}{$var} ? : 0 9 9
320  
321 # First part of subvar becomes var
322 9 ▶ if ($subvar && $subvar =~ /^\-\>(\w+)(.*)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($subvar and $subvar =~ /^\-\>(\w+)(.*)/) { } 9 0 9
Condition33%1/3
$subvar and $subvar =~ /^\-\>(\w+)(.*)/
!ll&&!rl&&r
009
MC/DC0%0/2
$subvar and $subvar =~ /^\-\>(\w+)(.*)/
$subvar $subvar =~ /^\-\>(\w+)(.*)/
Truth table33%1/3
A and B
A= $subvarB= $subvar =~ /^\-\>(\w+)(.*)/
ABresult
0X0
100
111
323 9 $var = $1;
324 9 $subvar = $2;
325 } else {
326 0 $var = '';
327 }
328 }
329  
330 207 $var = FindVar($self, $var, $subvar);
331  
332 207 ▶ if (!$type || $type eq '%') {
Branch: 4 branches
BranchTrueFalseTotal
if (not $type or $type eq '%') { } 191 16 207
elsif ($type eq '#') { } 3 13 16
elsif ($type eq '~') { } 0 13 13
elsif ($func) { } 9 4 13
Condition100%3/3
not $type or $type eq "%"
l!l&&r!l&&!r
189216
MC/DC100%2/2
not $type or $type eq "%"
not $type $type eq "%"
Truth table100%3/3
not(A) or B
A= not $typeB= $type eq "%"
ABresult
1X1
011
000
333 191 $var = $self->escapeHTML($var);
334 } elsif ($type eq '#') {
335 3 $var = CGI->escape($var);
336 } elsif ($type eq '~') {
337 0 ▶ my $dbh = $self->{'dbh'} || die "Not connected";
Condition0%0/2
$self->{'dbh'} || die('Not connected')
l!l
00
MC/DC0%0/1
$self->{'dbh'} || die('Not connected')
$self->{'dbh'}
Truth table0%0/2
A
A= $self->{'dbh'}
Aresult
11
00
338 0 $var = $dbh->quote($var);
339 } elsif ($func) {
340 9 $var = $self->$func($var);
341 }
342  
343 207 $var;
344 }
345  
346 208 ▶sub ParseVars ($$) {
Subroutine ParseVars: called CC=1 SCAR=0.0
Pod undocumented
347 208 my($self, $str) = @_;
348 208 $str =~ s/\$([\&\@\#\~\%]?)(\w+)((?:\-\>\w+)*)\$/$self->ParseVar($1,$2,$3)/eg;
349 208 $str;
350 }
351  
352  
353  
354 # For debugging
355 0 ▶sub Dump {
Subroutine Dump: not called CC=1 SCAR=6.9
Pod undocumented
356 0 my $self = shift;
357 0 require Data::Dumper;
358 0 Data::Dumper->new([@_])->Indent(1)->Terse(1)->Dump();
359 }
360  
361 0 ▶sub SetCookies {
Subroutine SetCookies: not called CC=3 SCAR=24.8
Pod undocumented
362 0 my $self = shift;
363 0 my @cookies = values %{$self->{'_ep_cookies'}};
364 0 ▶ return () unless @cookies;
Branch: 1 branch
BranchTrueFalseTotal
unless @cookies 0 0 0
365 print "Setting cookies:\n", $self->Dump(\@cookies), "\n"
366 0 ▶ if $self->{'debug'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 0 0
367 0 ('-cookie' => \@cookies);
368 }
369  
370  
371  
372 83 ▶sub EvalIf {
Subroutine EvalIf: called CC=18 SCAR=29.4
Pod undocumented
373 83 my($self, $tag, $attr) = @_;
374 83 my $debug = $self->{'debug'};
375 83 ▶ if (exists($attr->{'eval'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $attr->{"eval"}) 55 28 83
376 55 ▶ $self->print("$tag: Evaluating $attr->{'eval'}\n") if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 55 55
377 55 return $attr->{'eval'};
378 }
379 28 ▶ if (exists($attr->{'neval'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $attr->{"neval"}) 2 26 28
380 2 ▶ $self->print("$tag: Evaluating ! $attr->{'neval'}\n") if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 2 2
381 2 return !$attr->{'neval'};
382 }
383 26 ▶ die "Missing condition" unless(exists($attr->{'cnd'}));
Branch: 1 branch
BranchTrueFalseTotal
unless exists $attr->{"cnd"} 0 26 26
384 26 ▶ if ($attr->{'cnd'} =~ /^(.*?)(==|!=|<=?|>=?)(.*)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr->{"cnd"} =~ /^(.*?)(==|!=|<=?|>=?)(.*)$/) 22 4 26
385 22 ▶ $self->print("$tag: Numeric condition $1 $2 $3\n") if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 22 22
386 22 ▶ my $left = $1 || 0;
Condition50%1/2
$1 || 0
l!l
220
MC/DC0%0/1
$1 || 0
$1
Truth table50%1/2
A
A= $1
Aresult
11
00
387 22 my $cnd = $2;
388 22 ▶ my $right = $3 || 0;
Condition50%1/2
$3 || 0
l!l
220
MC/DC0%0/1
$3 || 0
$3
Truth table50%1/2
A
A= $3
Aresult
11
00
389 22 ▶ return ($left == $right) if $cnd eq '==';
Branch: 1 branch
BranchTrueFalseTotal
if $cnd eq "==" 3 19 22
390 19 ▶ return ($left != $right) if $cnd eq '!=';
Branch: 1 branch
BranchTrueFalseTotal
if $cnd eq "!=" 3 16 19
391 16 ▶ return ($left < $right) if $cnd eq '<';
Branch: 1 branch
BranchTrueFalseTotal
if $cnd eq "<" 7 9 16
392 9 ▶ return ($left > $right) if $cnd eq '>';
Branch: 1 branch
BranchTrueFalseTotal
if $cnd eq ">" 3 6 9
393 6 ▶ return ($left >= $right) if $cnd eq '>=';
Branch: 1 branch
BranchTrueFalseTotal
if $cnd eq ">=" 3 3 6
394 3 return ($left <= $right);
395 }
396 die "Cannot parse condition cnd=$attr->{'cnd'}"
397 4 ▶ unless $attr->{'cnd'} =~ /^\s*\'(.*?)\'\s*(eq|ne)\s*\'(.*)\'\s*$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $attr->{"cnd"} =~ /^\s*\'(.*?)\'\s*(eq|ne)\s*\'(.*)\'\s*$/ 0 4 4
398 4 ▶ $self->print("$tag: String condition $1 $2 $3\n") if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 4 4
399 4 ▶ return $1 eq $3 if $2 eq 'eq';
Branch: 1 branch
BranchTrueFalseTotal
if $2 eq "eq" 2 2 4
400 2 return $1 ne $3;
401 }
402  
403  
404  
405 16 ▶sub init { 1 }
Subroutine init: called CC=1 SCAR=0.0
Pod undocumented
406  
407 0 ▶sub Stop ($) { my($self) = @_; $self->{_ep_stop} = 1; }
Subroutine Stop: not called CC=1 SCAR=6.9
Pod undocumented
408  
409  
410 2 ▶sub _ep_comment {
Subroutine _ep_comment: called CC=1 SCAR=0.0
411 2 my $self = shift; my $attr = shift;
412 2 $self->AttrVal($attr->{'comment'}, @_);
413 2 '';
414 }
415  
416  
417 15 ▶sub _ep_package {
Subroutine _ep_package: called CC=9 SCAR=22.3
418 15 my $self = shift; my $attr = shift;
419 15 my $package = $attr->{name};
420 15 ▶ if (!exists($attr->{'require'}) || $attr->{'require'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $attr->{"require"} or $attr->{"require"}) 15 0 15
Condition33%1/3
not exists $attr->{"require"} or $attr->{"require"}
l!l&&r!l&&!r
1500
MC/DC0%0/2
not exists $attr->{"require"} or $attr->{"require"}
not exists $attr->{"require"} $attr->{"require"}
Truth table33%1/3
not(A) or B
A= not exists $attr->{"require"}B= $attr->{"require"}
ABresult
1X1
011
000
421 my @inc = ($ENV{'DOCUMENT_ROOT'} . $attr->{'lib'},
422 15 ▶ $attr->{'lib'}, @INC) if $attr->{'lib'};
Branch: 1 branch
BranchTrueFalseTotal
if $attr->{"lib"} 0 15 15
423 15 ▶ local @INC = @inc if @inc;
Branch: 1 branch
BranchTrueFalseTotal
if @inc 0 15 15
424 15 my $ppm = $package;
425 15 $ppm =~ s/\:\:/\//g;
426 15 require "$ppm.pm";
427 }
428  
429 15 ▶ my $pack = ($self->{'_ep_package'} || 0) + 1;
Condition100%2/2
$self->{'_ep_package'} || 0
l!l
114
MC/DC100%1/1
$self->{'_ep_package'} || 0
$self->{'_ep_package'}
Truth table100%2/2
A
A= $self->{'_ep_package'}
Aresult
11
00
430 15 ▶ if ($attr->{'isa'} || $self->{'_ep_package'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr->{'isa'} or $self->{'_ep_package'}) { } 1 14 15
Condition66%2/3
$attr->{"isa"} or $self->{"_ep_package"}
l!l&&r!l&&!r
0114
MC/DC50%1/2
$attr->{"isa"} or $self->{"_ep_package"}
$attr->{"isa"} $self->{"_ep_package"}
Truth table66%2/3
A or B
A= $attr->{"isa"}B= $self->{"_ep_package"}
ABresult
1X1
011
000
431 # If ep-package is called multiple times, or if $attr->{'isa'}
432 # is set, we create a new package and bless $self into it.
433 1 my @isa;
434 1 ▶ @isa = split(',', $attr->{'isa'}) if @isa;
Branch: 1 branch
BranchTrueFalseTotal
if @isa 0 1 1
435 1 my $p = ref($self);
436 10 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
437 1 push(@isa, $p);
438 1 my $bpack = "HTML::EP::PACK$pack";
439 1 @{"$bpack\::ISA"} = ($package, @isa);
440 1 bless($self, $bpack);
441 } else {
442 # Otherwise it's faster to bless $self into the package
443 14 bless($self, $package);
444 }
445 15 $self->{'_ep_package'} = $pack;
446  
447 15 $self->init($attr);
448 15 '';
449 }
450  
451 0 ▶sub _ep_debug {
Subroutine _ep_debug: not called CC=12 SCAR=50.5
452 0 my $self = shift;
453 0 my $cgi = $self->{'cgi'};
454  
455 0 my $debughosts = $self->{'_ep_config'}->{'debughosts'};
456 0 ▶ if ($debughosts) {
Branch: 1 branch
BranchTrueFalseTotal
if ($debughosts) 0 0 0
457 0 my $remoteip = '';
458 0 my $remotehost = '';
459 0 ▶ if ($self->{'_ep_r'} && (my $r = $self->{'_ep_r'})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'_ep_r'} and my $r = $self->{'_ep_r'}) { } 0 0 0
Condition0%0/3
$self->{"_ep_r"} and my $r = $self->{"_ep_r"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"_ep_r"} and my $r = $self->{"_ep_r"}
$self->{"_ep_r"} my $r = $self->{"_ep_r"}
Truth table0%0/3
A and B
A= $self->{"_ep_r"}B= my $r = $self->{"_ep_r"}
ABresult
0X0
100
111
460 0 ▶ $remoteip = ($r->connection()->remote_ip() || '');
Condition0%0/2
$r->connection->remote_ip || ''
l!l
00
MC/DC0%0/1
$r->connection->remote_ip || ''
$r->connection->remote_ip
Truth table0%0/2
A
A= $r->connection->remote_ip
Aresult
11
00
461 0 ▶ $remotehost = ($r->get_remote_host() || '');
Condition0%0/2
$r->get_remote_host || ''
l!l
00
MC/DC0%0/1
$r->get_remote_host || ''
$r->get_remote_host
Truth table0%0/2
A
A= $r->get_remote_host
Aresult
11
00
462 } else {
463 0 ▶ $remoteip = ($ENV{'REMOTE_ADDR'} || '');
Condition0%0/2
$ENV{'REMOTE_ADDR'} || ''
l!l
00
MC/DC0%0/1
$ENV{'REMOTE_ADDR'} || ''
$ENV{'REMOTE_ADDR'}
Truth table0%0/2
A
A= $ENV{'REMOTE_ADDR'}
Aresult
11
00
464 }
465 0 ▶ die "Debugging not permitted from $remoteip"
Branch: 1 branch
BranchTrueFalseTotal
if $remoteip and not $remoteip =~ /$debughosts/ and not $remotehost =~ /$debughosts/ 0 0 0
Condition0%0/6
$remoteip and not $remoteip =~ /$debughosts/ and not $remotehost =~ /$debughosts/
!ll&&!rl&&r
000
$remoteip and not $remoteip =~ /$debughosts/
!ll&&!rl&&r
000
MC/DC0%0/3
$remoteip and not $remoteip =~ /$debughosts/ and not $remotehost =~ /$debughosts/
$remoteip not $remoteip =~ /$debughosts/ not $remotehost =~ /$debughosts/
Truth table0%0/4
A and not(B) and not(C)
A= $remoteipB= not $remoteip =~ /$debughosts/C= not $remotehost =~ /$debughosts/
ABCresult
0XX0
10X0
1100
1111
466 . " ($remotehost), debug hosts = $debughosts"
467 if (($remoteip and $remoteip !~ /$debughosts/) and
468 ($remotehost !~ /$debughosts/));
469 }
470  
471 0 $| = 1;
472 0 $self->print($cgi->header('-type' => 'text/plain'));
473 0 $self->print("Entering debugging mode;",
474 " list of input values:\n");
475 0 foreach my $p ($cgi->param()) {
476 0 $self->print(" $p = ", $cgi->param($p), "\n");
477 }
478 0 ▶ $self->{'debug'} = $cgi->param('debug') || 1;
Condition0%0/2
$cgi->param('debug') || 1
l!l
00
MC/DC0%0/1
$cgi->param('debug') || 1
$cgi->param('debug')
Truth table0%0/2
A
A= $cgi->param('debug')
Aresult
11
00
479 0 '';
480 }
481  
482 2 ▶sub GetPerlCode {
Subroutine GetPerlCode: called CC=7 SCAR=32.9
Pod undocumented
483 2 my $self = shift; my $attr = shift;
484  
485 2 my $code;
486 2 ▶ if (my $file = $attr->{'src'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $file = $attr->{'src'}) { } 0 2 2
487 0 my $fh = Symbol::gensym();
488 0 ▶ if (! -f $file && -f ($self->{env}->{DOCUMENT_ROOT} . $file)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not -f $file and -f $self->{"env"}{"DOCUMENT_ROOT"} . $file) 0 0 0
Condition0%0/3
not -f $file and -f $self->{"env"}{"DOCUMENT_ROOT"} . $file
!ll&&!rl&&r
000
MC/DC0%0/2
not -f $file and -f $self->{"env"}{"DOCUMENT_ROOT"} . $file
not -f $file -f $self->{"env"}{"DOCUMENT_ROOT"} . $file
Truth table0%0/3
not(A) and B
A= not -f $fileB= -f $self->{"env"}{"DOCUMENT_ROOT"} . $file
ABresult
0X0
100
111
489 0 $file = ($self->{env}->{DOCUMENT_ROOT} . $file);
490 }
491 0 ▶ open($fh, "<$file") || die "Cannot open $file: $!";
Branch: 1 branch
BranchTrueFalseTotal
open $fh, "<$file" or die "Cannot open ${file}: $!" 0 0 0
492 0 local $/ = undef;
493 0 $code = <$fh>;
494 0 ▶ die "Error while reading $file: $!" unless defined($fh) and close($fh);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fh and close $fh 0 0 0
Condition0%0/3
defined $fh and close $fh
!ll&&!rl&&r
000
MC/DC0%0/2
defined $fh and close $fh
defined $fh close $fh
Truth table0%0/3
A and B
A= defined $fhB= close $fh
ABresult
0X0
100
111
495 } else {
496 2 $code = $self->AttrVal($attr->{'code'}, @_);
497 }
498 2 $code;
499 }
500  
501 2 ▶sub EvalPerlCode {
Subroutine EvalPerlCode: called CC=8 SCAR=28.7
Pod undocumented
502 2 my($self, $attr, $code) = @_;
503 2 my $output;
504 2 ▶ if ($attr->{'safe'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr->{'safe'}) { } 0 2 2
505 0 my $compartment = $self->{_ep_compartment};
506 0 ▶ if (!$compartment) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($compartment) 0 0 0
507 0 require Safe;
508 0 $compartment = $self->{_ep_compartment} = Safe->new();
509 }
510 0 ▶ if ($self->{debug}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"debug"}) 0 0 0
511 0 $self->print("Evaluating in Safe compartment:\n$code\n");
512 }
513 0 local $_ = $self; # The 'local' is required for garbage collection
514 0 $output = $compartment->reval($code);
515 } else {
516 $code = "package ".
517 2 ▶ ($attr->{'package'} || "HTML::EP::main").";".$code;
Condition50%1/2
$attr->{'package'} || 'HTML::EP::main'
l!l
02
MC/DC0%0/1
$attr->{'package'} || 'HTML::EP::main'
$attr->{'package'}
Truth table50%1/2
A
A= $attr->{'package'}
Aresult
11
00
518 2 ▶ $self->print("Evaluating script:\n$code\n") if $self->{'debug'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 2 2
519 2 local $_ = $self; # The 'local' is required for garbage collection
520 2 $output = eval $code;
521 }
522 2 ▶ die $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 2 2
523 $self->printf("Script returned:\n$output\nEnd of output.\n")
524 2 ▶ if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 2 2
525 2 $output;
526 }
527  
528 2 ▶sub EncodeByAttr {
Subroutine EncodeByAttr: called CC=7 SCAR=28.9
Pod undocumented
529 2 my($self, $attr, $str) = @_;
530 2 my $debug = $self->{'debug'};
531 2 ▶ $self->print("EncodeByAttr: Input $str\n") if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 2 2
532 2 ▶ if (my $type = $attr->{'output'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $type = $attr->{"output"}) 0 2 2
533 0 ▶ if ($type eq 'html') {
Branch: 3 branches
BranchTrueFalseTotal
if ($type eq 'html') { } 0 0 0
elsif ($type eq 'htmlbr') { } 0 0 0
elsif ($type eq 'url') { } 0 0 0
534 0 $str = $self->escapeHTML($str);
535 } elsif ($type eq 'htmlbr') {
536 0 $str = $self->escapeHTML($str);
537 0 $str =~ s/\n/<br>/sg;
538 } elsif ($type eq 'url') {
539 0 $str = CGI->escape($str);
540 }
541 }
542 2 ▶ $self->print("EncodeByAttr: Output $str\n") if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 2 2
543 2 $str;
544 }
545  
546 2 ▶sub _ep_perl {
Subroutine _ep_perl: called CC=2 SCAR=7.0
547 2 my $self = shift; my $attr = shift;
548 2 my $code = $self->GetPerlCode($attr, @_);
549 2 ▶ return undef unless defined $code;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $code 0 2 2
550 2 $self->EncodeByAttr($attr, $self->EvalPerlCode($attr, $code));
551 }
552  
553  
554 0 ▶sub _ep_database ($$;$) {
Subroutine _ep_database: not called CC=6 SCAR=37.4
555 0 my $self = shift; my $attr = shift;
556 0 ▶ my $dsn = $attr->{'dsn'} || $self->{env}->{DBI_DSN};
Condition0%0/3
$attr->{'dsn'} || $self->{'env'}{'DBI_DSN'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$attr->{'dsn'} || $self->{'env'}{'DBI_DSN'}
$attr->{'dsn'} $self->{'env'}{'DBI_DSN'}
Truth table0%0/3
A || B
A= $attr->{'dsn'}B= $self->{'env'}{'DBI_DSN'}
ABresult
1X1
011
000
557 0 ▶ my $user = $attr->{'user'} || $self->{env}->{DBI_USER};
Condition0%0/3
$attr->{'user'} || $self->{'env'}{'DBI_USER'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$attr->{'user'} || $self->{'env'}{'DBI_USER'}
$attr->{'user'} $self->{'env'}{'DBI_USER'}
Truth table0%0/3
A || B
A= $attr->{'user'}B= $self->{'env'}{'DBI_USER'}
ABresult
1X1
011
000
558 0 ▶ my $pass = $attr->{'password'} || $self->{env}->{DBI_PASS};
Condition0%0/3
$attr->{'password'} || $self->{'env'}{'DBI_PASS'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$attr->{'password'} || $self->{'env'}{'DBI_PASS'}
$attr->{'password'} $self->{'env'}{'DBI_PASS'}
Truth table0%0/3
A || B
A= $attr->{'password'}B= $self->{'env'}{'DBI_PASS'}
ABresult
1X1
011
000
559 0 ▶ my $dbhvar = $attr->{'dbh'} || 'dbh';
Condition0%0/2
$attr->{'dbh'} || 'dbh'
l!l
00
MC/DC0%0/1
$attr->{'dbh'} || 'dbh'
$attr->{'dbh'}
Truth table0%0/2
A
A= $attr->{'dbh'}
Aresult
11
00
560 0 require DBI;
561 $self->printf("Connecting to database: dsn = %s, user = %s,"
562 0 ▶ . " pass = %s\n", $dsn, $user, $pass) if $self->{'debug'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 0 0
563 0 $self->{$dbhvar} = DBI->connect($dsn, $user, $pass,
564 { 'RaiseError' => 1, 'Warn' => 0,
565 'PrintError' => 0 });
566 0 '';
567 }
568  
569  
570 0 ▶sub SqlSetupStatement {
Subroutine SqlSetupStatement: not called CC=8 SCAR=42.8
Pod undocumented
571 0 my($self, $attr, $dbh, $statement) = @_;
572  
573 0 ▶ my $start_at = $attr->{'startat'} || 0;
Condition0%0/2
$attr->{'startat'} || 0
l!l
00
MC/DC0%0/1
$attr->{'startat'} || 0
$attr->{'startat'}
Truth table0%0/2
A
A= $attr->{'startat'}
Aresult
11
00
574 0 ▶ my $limit = $attr->{'limit'} || -1;
Condition0%0/2
$attr->{'limit'} || -1
l!l
00
MC/DC0%0/1
$attr->{'limit'} || -1
$attr->{'limit'}
Truth table0%0/2
A
A= $attr->{'limit'}
Aresult
11
00
575 0 ▶ if (($start_at || $limit != -1) &&
Branch: 1 branch
BranchTrueFalseTotal
if ($start_at || $limit != -1 and $dbh->{"ImplementorClass"} eq "DBD::mysql::db") 0 0 0
Condition0%0/6
$start_at || $limit != -1 and $dbh->{"ImplementorClass"} eq "DBD::mysql::db"
!ll&&!rl&&r
000
$start_at or $limit != -1
l!l&&r!l&&!r
000
MC/DC0%0/3
$start_at || $limit != -1 and $dbh->{"ImplementorClass"} eq "DBD::mysql::db"
$start_at $limit != -1 $dbh->{"ImplementorClass"} eq "DBD::mysql::db"
Truth table0%0/5
A or B and C
A= $start_atB= $limit != -1C= $dbh->{"ImplementorClass"} eq "DBD::mysql::db"
ABCresult
00X0
1X00
0100
1X11
0111
576 $dbh->{'ImplementorClass'} eq 'DBD::mysql::db') {
577 0 $statement .= " LIMIT $start_at, $limit";
578 0 $start_at = 0;
579 }
580 0 ▶ if ($self->{'debug'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"debug"}) 0 0 0
581 0 $self->print("Executing query, statement = $statement\n");
582 $self->printf("Result starting at row %s\n",
583 0 ▶ $attr->{'startat'} || 0);
Condition0%0/2
$attr->{'startat'} || 0
l!l
00
MC/DC0%0/1
$attr->{'startat'} || 0
$attr->{'startat'}
Truth table0%0/2
A
A= $attr->{'startat'}
Aresult
11
00
584 0 $self->printf("Rows limited to %s\n", $attr->{'limit'});
585 }
586 0 my $sth = $dbh->prepare($statement);
587 0 $sth->execute();
588 0 ($sth, $start_at, $limit)
589 }
590  
591 0 ▶sub SqlSetupResult {
Subroutine SqlSetupResult: not called CC=12 SCAR=50.5
Pod undocumented
592 0 my($self, $attr, $sth, $start_at, $limit) = @_;
593 0 my $result = $attr->{'result'};
594 0 my $list = [];
595 0 my $ref;
596 0 ▶ while ($limit && $start_at-- > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($limit and $start_at-- > 0) 0 0 0
Condition0%0/3
$limit and $start_at-- > 0
!ll&&!rl&&r
000
MC/DC0%0/2
$limit and $start_at-- > 0
$limit $start_at-- > 0
Truth table0%0/3
A and B
A= $limitB= $start_at-- > 0
ABresult
0X0
100
111
597 0 ▶ if (!$sth->fetchrow_arrayref()) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($sth->fetchrow_arrayref) 0 0 0
598 0 $limit = 0;
599 0 last;
600 }
601 }
602 my $resultmethod =
603 0 ▶ (exists($attr->{'resulttype'}) && $attr->{'resulttype'} =~ /array/) ?
Branch: 1 branch
BranchTrueFalseTotal
exists $attr->{'resulttype'} && $attr->{'resulttype'} =~ /array/ ? : 0 0 0
Condition0%0/3
exists $attr->{"resulttype"} and $attr->{"resulttype"} =~ /array/
!ll&&!rl&&r
000
MC/DC0%0/2
exists $attr->{"resulttype"} and $attr->{"resulttype"} =~ /array/
exists $attr->{"resulttype"} $attr->{"resulttype"} =~ /array/
Truth table0%0/3
A and B
A= exists $attr->{"resulttype"}B= $attr->{"resulttype"} =~ /array/
ABresult
0X0
100
111
604 "fetchrow_arrayref" : "fetchrow_hashref";
605 0 ▶ while ($limit-- && ($ref = $sth->$resultmethod())) {
Branch: 1 branch
BranchTrueFalseTotal
if ($limit-- and $ref = $sth->$resultmethod) 0 0 0
Condition0%0/3
$limit-- and $ref = $sth->$resultmethod
!ll&&!rl&&r
000
MC/DC0%0/2
$limit-- and $ref = $sth->$resultmethod
$limit-- $ref = $sth->$resultmethod
Truth table0%0/3
A and B
A= $limit--B= $ref = $sth->$resultmethod
ABresult
0X0
100
111
606 0 ▶ push(@$list, (ref($ref) eq 'ARRAY') ? [@$ref] : {%$ref});
Branch: 1 branch
BranchTrueFalseTotal
ref $ref eq 'ARRAY' ? : 0 0 0
607 }
608 0 ▶ if (exists($attr->{'resulttype'}) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $attr->{'resulttype'} and $attr->{'resulttype'} =~ /^single_/) { } 0 0 0
Condition0%0/3
exists $attr->{"resulttype"} and $attr->{"resulttype"} =~ /^single_/
!ll&&!rl&&r
000
MC/DC0%0/2
exists $attr->{"resulttype"} and $attr->{"resulttype"} =~ /^single_/
exists $attr->{"resulttype"} $attr->{"resulttype"} =~ /^single_/
Truth table0%0/3
A and B
A= exists $attr->{"resulttype"}B= $attr->{"resulttype"} =~ /^single_/
ABresult
0X0
100
111
609 $attr->{'resulttype'} =~ /^single_/) {
610 0 $self->{$result} = $list->[0];
611 } else {
612 0 $self->{$result} = $list;
613 }
614 0 $self->{"$result\_rows"} = scalar(@$list);
615 0 ▶ $self->print("Result: ", scalar(@$list), " rows.\n") if $self->{'debug'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 0 0
616 }
617  
618 0 ▶sub _ep_query {
Subroutine _ep_query: not called CC=5 SCAR=34.0
619 0 my($self, $attr, $tokens, $token) = @_;
620 0 my $debug = $self->{'debug'};
621 0 my $statement = $self->AttrVal($attr->{'statement'}, $tokens, $token, 1);
622 0 ▶ my $dbh = $self->{$attr->{'dbh'} || 'dbh'} || die "Not connected";
Condition0%0/4
$$self{$attr->{'dbh'} or 'dbh'} || die('Not connected')
l!l
00
$attr->{'dbh'} || 'dbh'
l!l
00
MC/DC0%0/1
$$self{$attr->{'dbh'} or 'dbh'} || die('Not connected')
$$self{$attr->{'dbh'} or 'dbh'}
MC/DC0%0/1
$attr->{'dbh'} || 'dbh'
$attr->{'dbh'}
Truth table0%0/2
A
A= $$self{$attr->{'dbh'} or 'dbh'}
Aresult
11
00
Truth table0%0/2
A
A= $attr->{'dbh'}
Aresult
11
00
623 0 ▶ if (!exists($attr->{'result'})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $attr->{"result"}) 0 0 0
624 0 ▶ $self->print("Doing Query: $statement\n") if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 0 0
625 0 $dbh->do($statement);
626 0 return '';
627 }
628  
629 0 $self->SqlSetupResult($attr,
630 $self->SqlSetupStatement($attr, $dbh, $statement));
631 0 '';
632 }
633  
634  
635 1 ▶sub _ep_select ($$;$) {
Subroutine _ep_select: called CC=3 SCAR=11.0
636 1 my $self = shift; my $attr = shift;
637 1 my @tags;
638 1 ▶ while (my($var, $val) = each %$attr) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$attr) 4 1 5
639 4 ▶ if ($var !~ /^template|range|format|items?|selected(?:\-text)?$/i){
Branch: 1 branch
BranchTrueFalseTotal
unless ($var =~ /^template|range|format|items?|selected(?:\-text)?$/i) 1 3 4
640 1 push(@tags, sprintf('%s="%s"', $var, $self->escapeHTML($val)));
641 }
642 }
643  
644 1 $attr->{'format'} = '<SELECT ' . join(" ", @tags) . '>$@output$</SELECT>';
645 1 $self->_ep_list($attr, @_);
646 }
647  
648  
649 20 ▶sub _ep_list {
Subroutine _ep_list: called CC=16 SCAR=29.1
650 20 my($self, $attr, $tokens, $token) = @_;
651 20 my $debug = $self->{'debug'};
652 20 my $template;
653 20 ▶ if (defined($attr->{'template'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $attr->{'template'}) { } 0 20 20
654 0 my $parser = HTML::EP::Parser->new();
655 0 $parser->text($attr->{'template'});
656 0 $template = HTML::EP::Tokens->new('tokens' => $parser->{'_ep_tokens'});
657 } else {
658 20 my $first = $tokens->First();
659 20 my $last = $self->FindEndTag($tokens, $token->{'tag'});
660 20 $template = $tokens->Clone($first, $last-1);
661 }
662 20 my $output = '';
663 20 my($list, $range);
664 20 ▶ if ($range = $attr->{'range'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($range = $attr->{'range'}) { } 16 4 20
665 16 ▶ $list = [ map { $_ =~ /(\d+)\.\.(\d+)/ ? ($1 .. $2) : $_}
Branch: 1 branch
BranchTrueFalseTotal
$_ =~ /(\d+)\.\.(\d+)/ ? : 16 0 16
666 split(/,/, $range) ];
667 } else {
668 4 my $items = $attr->{'items'};
669 $list = ref($items) ? $items :
670 ($items =~ /^(\w+)((?:\-\>\w+)+)$/) ?
671 4 ▶ $self->FindVar($1, $2) : $self->{$items};
Branch: 2 branches
BranchTrueFalseTotal
ref $items ? : 0 4 4
$items =~ /^(\w+)((?:\-\>\w+)+)$/ ? : 1 3 4
672 }
673 20 ▶ $self->print("_ep_list: Template = $template, Items = ", @$list, "\n")
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 20 20
674 if $debug;
675 20 ▶ my $l = $attr->{'item'} or die "Missing item name";
Branch: 1 branch
BranchTrueFalseTotal
my $l = $attr->{"item"} or die "Missing item name" 20 0 20
676 20 my $i = 0;
677 20 my $selected = $attr->{'selected'};
678 20 my $isSelected;
679 20 foreach my $ref (@$list) {
680 66 $self->{$l} = $ref;
681 66 ▶ $self->{'i'} = $i++ unless $l eq 'i';
Branch: 1 branch
BranchTrueFalseTotal
unless $l eq "i" 66 0 66
682 66 ▶ if ($selected) {
Branch: 1 branch
BranchTrueFalseTotal
if ($selected) 5 61 66
683 5 ▶ if (ref($ref) eq 'HASH') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $ref eq 'HASH') { } 0 5 5
elsif (ref $ref eq 'ARRAY') { } 0 5 5
684 0 $isSelected = $ref->{'val'} eq $selected;
685 } elsif (ref($ref) eq 'ARRAY') {
686 0 $isSelected = $ref->[0] eq $selected;
687 } else {
688 5 $isSelected = $ref eq $selected;
689 }
690 $self->{'selected'} = $isSelected ?
691 5 ▶ ($attr->{'selected-text'} || 'SELECTED') : '';
Branch: 1 branch
BranchTrueFalseTotal
$isSelected ? : 1 4 5
Condition50%1/2
$attr->{"selected-text"} or "SELECTED"
l!l
01
MC/DC0%0/1
$attr->{"selected-text"} or "SELECTED"
$attr->{"selected-text"}
Truth table50%1/2
A
A= $attr->{"selected-text"}
Aresult
11
00
692 }
693 66 $output .= $self->ParseVars($self->RepeatedTokenMarch($template));
694 }
695 20 ▶ if (my $format = $attr->{'format'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $format = $attr->{'format'}) { } 1 19 20
696 1 $attr->{'output'} = $output;
697 1 $format =~ s/\$([\@\#\~]?)(\w+)((?:\-\>\w+)*)\$/HTML::EP::ParseVar($attr, $1, $2, $3)/eg;
698 1 $format;
699 } else {
700 19 $output;
701 }
702 }
703  
704  
705 1 ▶sub _ep_errhandler {
Subroutine _ep_errhandler: called CC=4 SCAR=15.0
706 1 my $self = shift; my $attr = shift;
707 1 my $type = $attr->{type};
708 1 ▶ $type = ($type && (lc $type) eq 'user') ? 'user' : 'system';
Branch: 1 branch
BranchTrueFalseTotal
$type && lc $type eq 'user' ? : 0 1 1
Condition33%1/3
$type and lc $type eq "user"
!ll&&!rl&&r
100
MC/DC0%0/2
$type and lc $type eq "user"
$type lc $type eq "user"
Truth table33%1/3
A and B
A= $typeB= lc $type eq "user"
ABresult
0X0
100
111
709 1 ▶ if ($attr->{src}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr->{'src'}) { } 0 1 1
710 0 $self->{"_ep_err_file_$type"} = $attr->{src};
711 } else {
712 1 my $template = $self->AttrVal($attr->{'template'}, @_);
713 1 $self->{"_ep_err_msg_$type"} = $template;
714 }
715 1 '';
716 }
717  
718  
719 2 ▶sub _ep_error {
Subroutine _ep_error: called CC=3 SCAR=12.3
720 2 my($self, $attr, $tokens, $token) = @_;
721 2 my $msg = $self->AttrVal($attr->{'msg'}, $tokens, $token, 1);
722 2 my $type = $attr->{'type'};
723 2 ▶ $self->{_ep_err_type} = ($type && (lc $type) eq 'user') ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$type && lc $type eq 'user' ? : 0 2 2
Condition33%1/3
$type and lc $type eq "user"
!ll&&!rl&&r
200
MC/DC0%0/2
$type and lc $type eq "user"
$type lc $type eq "user"
Truth table33%1/3
A and B
A= $typeB= lc $type eq "user"
ABresult
0X0
100
111
724 2 die $msg;
725 0 '';
726 }
727  
728  
729 0 ▶sub _ep_input_sql_query {
Subroutine _ep_input_sql_query: not called CC=10 SCAR=47.0
730 0 my $self = shift; my $attr = shift;
731 0 ▶ my $dbh = $self->{'dbh'} ||
Condition0%0/2
$self->{'dbh'} || die('Missing database-handle (Did you run ep-database?)')
l!l
00
MC/DC0%0/1
$self->{'dbh'} || die('Missing database-handle (Did you run ep-database?)')
$self->{'dbh'}
Truth table0%0/2
A
A= $self->{'dbh'}
Aresult
11
00
732 die "Missing database-handle (Did you run ep-database?)";
733 0 ▶ my $dest = $attr->{'dest'} ||
Condition0%0/2
$attr->{'dest'} || die(q[Missing attribute 'dest' (Destination variable)])
l!l
00
MC/DC0%0/1
$attr->{'dest'} || die(q[Missing attribute 'dest' (Destination variable)])
$attr->{'dest'}
Truth table0%0/2
A
A= $attr->{'dest'}
Aresult
11
00
734 die "Missing attribute 'dest' (Destination variable)";
735 0 my $debug = $self->{'debug'};
736  
737 0 my $names = '';
738 0 my $values = '';
739 0 my $update = '';
740 0 my $comma = '';
741 0 ▶ while (my($var, $val) = each %{$self->{$dest}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$$self{$dest};}) 0 0 0
742 0 $names .= $comma . $var;
743 0 my $v = $val->{'val'};
744 0 ▶ $v = $dbh->quote($v) if !defined($v) || $val->{'type'} ne 'n';
Branch: 1 branch
BranchTrueFalseTotal
if not defined $v or $val->{"type"} ne "n" 0 0 0
Condition0%0/3
not defined $v or $val->{"type"} ne "n"
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $v or $val->{"type"} ne "n"
not defined $v $val->{"type"} ne "n"
Truth table0%0/3
not(A) or B
A= not defined $vB= $val->{"type"} ne "n"
ABresult
1X1
011
000
745 0 $values .= $comma . $v;
746 0 $update .= $comma . "$var=$v";
747 0 ▶ $comma = ',' unless $comma;
Branch: 1 branch
BranchTrueFalseTotal
unless $comma 0 0 0
748 }
749 0 my $hash = $self->{$dest};
750 0 $hash->{'names'} = $names;
751 0 ▶ print "_ep_input_sql_query: Setting $dest\->names to $names\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 0 0
752 0 $hash->{'values'} = $values;
753 0 ▶ print "_ep_input_sql_query: Setting $dest\->values to $values\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 0 0
754 0 $hash->{'update'} = $update;
755 0 ▶ print "_ep_input_sql_query: Setting $dest\->update to $update\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 0 0
756 0 '';
757 }
758  
759 2 ▶sub _ep_input {
Subroutine _ep_input: called CC=19 SCAR=30.0
760 2 my($self, $attr) = @_;
761 2 my $prefix = $attr->{'prefix'};
762 2 my($var, $val);
763 2 my $cgi = $self->{'cgi'};
764 2 my @params = $cgi->param();
765 2 my $i = 0;
766 2 my $list = $attr->{'list'};
767 2 my $dest = $attr->{'dest'};
768  
769 2 ▶ $self->{$dest} = [] if $list;
Branch: 1 branch
BranchTrueFalseTotal
if $list 1 1 2
770 2 while(1) {
771 4 my $p = $prefix;
772 4 my $hash = {};
773 4 ▶ if ($list) {
Branch: 1 branch
BranchTrueFalseTotal
if ($list) 3 1 4
774 3 $p .= "$i\_";
775 }
776 4 foreach $var (@params) {
777 25 ▶ if ($var =~ /^\Q$p\E\_?(\w+?)_(.*)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($var =~ /^\Q$p\E\_?(\w+?)_(.*)$/) 17 8 25
778 17 my $col = $2;
779 17 my $type = $1;
780 17 ▶ if ($type =~ /^d[dmy]$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type =~ /^d[dmy]$/) { } 9 8 17
781 # A date
782 9 ▶ if ($hash->{$col}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hash->{$col}) 6 3 9
783 # Do this only once
784 6 next;
785 }
786 3 ▶ if (!$hash->{$col}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($hash->{$col}) 3 0 3
787 3 my $year = $cgi->param("${p}dy_$col");
788 3 my $month = $cgi->param("${p}dm_$col");
789 3 my $day = $cgi->param("${p}dd_$col");
790 3 ▶ if ($year eq '' && $month eq '' && $day eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($year eq '' and $month eq '' and $day eq '') { } 0 3 3
Condition33%2/6
$year eq "" and $month eq "" and $day eq ""
!ll&&!rl&&r
300
$year eq "" and $month eq ""
!ll&&!rl&&r
300
MC/DC0%0/3
$year eq "" and $month eq "" and $day eq ""
$year eq "" $month eq "" $day eq ""
Truth table25%1/4
A and B and C
A= $year eq ""B= $month eq ""C= $day eq ""
ABCresult
0XX0
10X0
1100
1111
791 0 $val = undef;
792 } else {
793 3 ▶ if ($year < 20) {
Branch: 2 branches
BranchTrueFalseTotal
if ($year < 20) { } 1 2 3
elsif ($year < 100) { } 1 1 2
794 1 $year += 2000;
795 } elsif ($year < 100) {
796 1 $year += 1900;
797 }
798 3 $val = sprintf("%04d-%02d-%02d",
799 $year, $month, $day);
800 }
801 3 $hash->{$col} = { col => $col,
802 val => $val,
803 type => 'd',
804 year => $year,
805 month => $month,
806 day => $day
807 };
808 }
809 } else {
810 8 ▶ $val = ($type eq 's') ?
Branch: 1 branch
BranchTrueFalseTotal
$type eq 's' ? : 0 8 8
811 join(",", $cgi->param($var)) : $cgi->param($var);
812 8 $hash->{$col} = { col => $col,
813 type => $type,
814 val => $val
815 };
816 }
817 }
818 }
819 4 ▶ if ($list) {
Branch: 1 branch
BranchTrueFalseTotal
if ($list) { } 3 1 4
820 die "Cannot create 'names', 'values' and 'update' attributes"
821 3 ▶ . " if 'list' is set." if $attr->{'sqlquery'};
Branch: 1 branch
BranchTrueFalseTotal
if $attr->{"sqlquery"} 0 3 3
822 3 ▶ last unless %$hash;
Branch: 1 branch
BranchTrueFalseTotal
unless %$hash 1 2 3
823 2 $hash->{'i'} = $i++;
824 2 push(@{$self->{$dest}}, $hash);
825 } else {
826 1 $self->{$dest} = $hash;
827 1 ▶ $self->_ep_input_sql_query($attr) if $attr->{'sqlquery'};
Branch: 1 branch
BranchTrueFalseTotal
if $attr->{"sqlquery"} 0 1 1
828 1 last;
829 }
830 }
831 2 ▶ if ($self->{'debug'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"debug"}) 0 2 2
832 $self->print("_ep_input: Gelesene Daten\n",
833 0 $self->Dump($self->{$dest}));
834 }
835 2 '';
836 }
837  
838 59 ▶sub _ep_if {
Subroutine _ep_if: called CC=16 SCAR=27.7
839 59 my($self, $attr, $tokens, $token) = @_;
840 59 my $level = 0;
841 59 my $tag = $token->{'tag'};
842 59 my $state = $self->EvalIf($tag, $attr);
843 59 ▶ my $start = $tokens->First() if $state;
Branch: 1 branch
BranchTrueFalseTotal
if $state 26 33 59
844 59 my $state_done = $state;
845 59 my $last;
846 59 ▶ while (defined(my $token = $tokens->Token())) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $token = $tokens->Token)) 371 0 371
847 371 ▶ if ($token->{'type'} eq 'S') {
Branch: 2 branches
BranchTrueFalseTotal
if ($token->{'type'} eq 'S') { } 130 241 371
elsif ($token->{'type'} eq 'E') { } 71 170 241
848 130 ▶ if ($token->{'tag'} eq 'ep-if') {
Branch: 2 branches
BranchTrueFalseTotal
if ($token->{'tag'} eq 'ep-if') { } 10 120 130
elsif ($token->{'tag'} =~ /^ep-els(?:e|e?if)?$/) { } 114 6 120
849 10 ++$level;
850 } elsif ($token->{'tag'} =~ /^ep-els(?:e|e?if)?$/) {
851 114 ▶ next if $level;
Branch: 1 branch
BranchTrueFalseTotal
if $level 18 96 114
852 96 ▶ if ($state) {
Branch: 2 branches
BranchTrueFalseTotal
if ($state) { } 31 65 96
elsif (not $state_done) { } 42 23 65
853 31 $last = $tokens->First()-1;
854 31 $state = 0;
855 } elsif (!$state_done) {
856 42 ▶ if ($state = $token->{'tag'} eq 'ep-else' ||
Branch: 1 branch
BranchTrueFalseTotal
if ($state = $token->{"tag"} eq "ep-else" || $self->EvalIf($tag, $self->ParseAttr($token->{"attr"}))) 29 13 42
Condition100%3/3
$token->{'tag'} eq 'ep-else' || $self->EvalIf($tag, $self->ParseAttr($token->{'attr'}))
l!l&&r!l&&!r
181113
MC/DC100%2/2
$token->{'tag'} eq 'ep-else' || $self->EvalIf($tag, $self->ParseAttr($token->{'attr'}))
$token->{'tag'} eq 'ep-else' $self->EvalIf($tag, $self->ParseAttr($token->{'attr'}))
Truth table100%3/3
A || B
A= $token->{'tag'} eq 'ep-else'B= $self->EvalIf($tag, $self->ParseAttr($token->{'attr'}))
ABresult
1X1
011
000
857 $self->EvalIf
858 ($tag, $self->ParseAttr($token->{'attr'}))) {
859 29 $state_done = 1;
860 29 $start = $tokens->First();
861 }
862 }
863 }
864 } elsif ($token->{'type'} eq 'E') {
865 71 ▶ if ($token->{'tag'} eq 'ep-if') {
Branch: 1 branch
BranchTrueFalseTotal
if ($token->{"tag"} eq "ep-if") 69 2 71
866 69 ▶ next if $level--;
Branch: 1 branch
BranchTrueFalseTotal
if $level-- 10 59 69
867 59 ▶ return '' unless $state_done;
Branch: 1 branch
BranchTrueFalseTotal
unless $state_done 4 55 59
868 55 ▶ $last = $tokens->First()-1 if $state;
Branch: 1 branch
BranchTrueFalseTotal
if $state 24 31 55
869 55 return $self->TokenMarch($tokens->Clone($start, $last));
870 }
871 }
872 }
873 0 die "ep-if without /ep-if";
874 }
875  
876 0 ▶sub _ep_elseif { die "ep-elseif without ep-if" }
Subroutine _ep_elseif: not called CC=1 SCAR=6.9
877 0 ▶sub _ep_elsif { die "ep-elsif without ep-if" }
Subroutine _ep_elsif: not called CC=1 SCAR=6.9
878 0 ▶sub _ep_else { die "ep-else without ep-if" }
Subroutine _ep_else: not called CC=1 SCAR=6.9
879  
880  
881 0 ▶sub _ep_mail {
Subroutine _ep_mail: not called CC=10 SCAR=47.0
882 0 my($self, $attr, $tokens, $token) = @_;
883  
884 my $host = (delete $attr->{'mailserver'}) ||
885 0 ▶ $self->{'_ep_config'}->{'mailhost'} || '127.0.0.1';
Condition0%0/5
delete $attr->{'mailserver'} || $self->{'_ep_config'}{'mailhost'} || '127.0.0.1'
l!l
00
delete $attr->{"mailserver"} or $self->{"_ep_config"}{"mailhost"}
l!l&&r!l&&!r
000
MC/DC0%0/2
delete $attr->{'mailserver'} || $self->{'_ep_config'}{'mailhost'} || '127.0.0.1'
delete $attr->{"mailserver"} $self->{"_ep_config"}{"mailhost"}
Truth table0%0/3
A or B
A= delete $attr->{"mailserver"}B= $self->{"_ep_config"}{"mailhost"}
ABresult
1X1
011
000
886 0 my @options;
887 0 my $body = $self->AttrVal($attr->{'body'}, $tokens, $token, 1);
888 0 require Mail::Header;
889 0 my $msg = Mail::Header->new();
890 0 my($header, $val);
891 0 ▶ my $from = $attr->{'from'} || die "Missing header attribute: from";
Condition0%0/2
$attr->{'from'} || die('Missing header attribute: from')
l!l
00
MC/DC0%0/1
$attr->{'from'} || die('Missing header attribute: from')
$attr->{'from'}
Truth table0%0/2
A
A= $attr->{'from'}
Aresult
11
00
892 0 ▶ die "Missing header attribute: to" unless $attr->{'to'};
Branch: 1 branch
BranchTrueFalseTotal
unless $attr->{"to"} 0 0 0
893 0 ▶ die "Missing header attribute: subject" unless $attr->{'subject'};
Branch: 1 branch
BranchTrueFalseTotal
unless $attr->{"subject"} 0 0 0
894 0 ▶ while (($header, $val) = each %$attr) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$attr) 0 0 0
895 0 $msg->add($header, $val);
896 }
897 0 require Net::SMTP;
898 0 require Mail::Internet;
899 0 my $debug = $self->{'debug'};
900 0 ▶ local *STDERR if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 0 0
901 0 ▶ if ($debug) {
Branch: 1 branch
BranchTrueFalseTotal
if ($debug) 0 0 0
902 0 $self->print("Headers: \n");
903 0 $self->print($msg->as_string());
904 0 $self->print("Making SMTP connection to $host.\n");
905 0 open(STDERR, ">&STDOUT");
906 }
907 0 ▶ my $smtp = Net::SMTP->new($host, 'Debug' => $debug)
Branch: 1 branch
BranchTrueFalseTotal
my $smtp = "Net::SMTP"->new($host, "Debug", $debug) or die "Cannot open SMTP connection to ${host}: $!" 0 0 0
908 or die "Cannot open SMTP connection to $host: $!";
909 0 my $mail = Mail::Internet->new([$body], Header => $msg);
910 0 $Mail::Util::mailaddress = $from; # Ugly hack to prevent
911 # DNS lookup for 'mailhost'
912 # in Mail::Util::mailaddress().
913 0 $mail->smtpsend('Host' => $smtp, @options);
914 0 $smtp->quit();
915 0 '';
916 }
917  
918  
919 3 ▶sub _ep_include {
Subroutine _ep_include: called CC=5 SCAR=16.5
920 3 my($self, $attr, $tokens, $token) = @_;
921 3 my $parser = HTML::EP::Parser->new();
922 3 ▶ my $f = $attr->{'file'} || die "Missing file name\n";
Condition50%1/2
$attr->{'file'} || die("Missing file name\n")
l!l
30
MC/DC0%0/1
$attr->{'file'} || die("Missing file name\n")
$attr->{'file'}
Truth table50%1/2
A
A= $attr->{'file'}
Aresult
11
00
923 3 my $df = $self->{'env'}->{'DOCUMENT_ROOT'} . $f;
924 3 ▶ $f = $df if -f $df;
Branch: 1 branch
BranchTrueFalseTotal
if -f $df 3 0 3
925 3 my $fh = Symbol::gensym();
926 3 ▶ open($fh, "<$f") || die "Failed to open file $f: $!";
Branch: 1 branch
BranchTrueFalseTotal
open $fh, "<$f" or die "Failed to open file ${f}: $!" 3 0 3
927 3 $parser->parse_file($fh);
928 3 $parser->eof();
929 3 my $new_toks = HTML::EP::Tokens->new('tokens' => $parser->{'_ep_tokens'});
930 3 ▶ $tokens->Replace
Branch: 1 branch
BranchTrueFalseTotal
if $tokens 3 0 3
931 ($tokens->First()-1,
932 { 'type' => 'I',
933 'tokens' => $new_toks
934 }) if $tokens; # Upwards compatibility: Before EP 0.20 users
935 # didn't pass a tokens argument.
936 3 $self->RepeatedTokenMarch($new_toks)
937 }
938  
939  
940 3 ▶sub _ep_exit {
Subroutine _ep_exit: called CC=1 SCAR=0.0
941 3 my $self = shift;
942 # If we are inside of an ep-if, we need to collect previous output
943 3 $self->{'_ep_output'} = join('', @{$self->{'_ep_output_stack'}},
944 3 $self->{'_ep_output'});
945 3 die "_ep_exit, ignore";
946 }
947  
948 0 ▶sub _ep_redirect {
Subroutine _ep_redirect: not called CC=4 SCAR=30.0
949 0 my $self = shift; my $attr = shift;
950 0 ▶ my $to = $attr->{'to'} or die "Missing redirect target";
Branch: 1 branch
BranchTrueFalseTotal
my $to = $attr->{"to"} or die "Missing redirect target" 0 0 0
951 0 ▶ $self->print("Redirecting to $to\n") if $self->{'debug'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 0 0
952 $self->print($self->{'cgi'}->redirect('-uri' => $to,
953 '-type' => 'text/plain',
954 '-refresh' => "0; URL=$to",
955 0 ▶ $attr->{'cookies'} ?
Branch: 1 branch
BranchTrueFalseTotal
$attr->{'cookies'} ? : 0 0 0
956 $self->SetCookies() : ()));
957 0 $self->print('<BODY BGCOLOR="#FFFFFF">Click <A HREF="', $to,
958 '">here</A> to go on</BODY>');
959 0 $self->Stop();
960 0 '';
961 }
962  
963 8 ▶sub _ep_set {
Subroutine _ep_set: called CC=5 SCAR=16.2
964 8 my($self, $attr, $tokens, $token) = @_;
965 my $val = $self->AttrVal($attr->{'val'}, $tokens, $token,
966 8 !$attr->{'noparse'});
967 8 my $var = $attr->{'var'};
968 8 my $ref = $self;
969 8 ▶ while ($var =~ /(.*?)\-\>(.*)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($var =~ /(.*?)\-\>(.*)/) 2 8 10
970 2 my $key = $1;
971 2 $var = $2;
972 2 ▶ if ($key =~ /^\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($key =~ /^\d+$/) { } 0 2 2
973 0 $ref = $ref->[$key];
974 } else {
975 2 $ref = $ref->{$key};
976 }
977 }
978 8 ▶ print "Setting $ref -> $var to $val\n" if $self->{'debug'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 8 8
979 8 ▶ if ($var =~ /^\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($var =~ /^\d+$/) { } 1 7 8
980 1 $ref->[$var] = $val;
981 } else {
982 7 $ref->{$var} = $val;
983 }
984 8 '';
985 }
986  
987 2 ▶sub _format_NBSP {
Subroutine _format_NBSP: called CC=3 SCAR=11.0
988 2 my $self = shift; my $str = shift;
989 2 ▶ if (!defined($str) || $str eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $str or $str eq "") 1 1 2
Condition66%2/3
not defined $str or $str eq ""
l!l&&r!l&&!r
011
MC/DC50%1/2
not defined $str or $str eq ""
not defined $str $str eq ""
Truth table66%2/3
not(A) or B
A= not defined $strB= $str eq ""
ABresult
1X1
011
000
990 1 $str = '&nbsp;';
991 }
992 2 $str;
993 }
994  
995  
996 10 1;
« blib/lib/HTML/EP/Session.pm ↑ Summary blib/lib/HTML/EP/Session/Dumper.pm »