blib/lib/CGI/apacheSSI.pm

filter: Statementstmt 48.3% 250 / 517 Branchbran 25.9% 85 / 328 Conditioncond 38.5% 32 / 83 MC/DCmcdc 14.8% 7 / 47 Subroutinesub 68.9% 40 / 58 Podpod 66.6% 14 / 21 totaltotal 40.6% 428 / 1054 CC 195 SCAR 62.6
CC
195
Cov
40%
_test
2550.0
elif
110.0
fsize
65.0
CRAP 524.6
↑ Summary
1 package CGI::apacheSSI;
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3
4 # use HTML::SimpleParse;
5 2 ▶use File::Spec::Functions; # catfile()
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use FindBin;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use HTTP::Response;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use HTTP::Cookies;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Date::Format;
Subroutine BEGIN: called CC=1 SCAR=0.0
12
13 2 our $VERSION = '0.94';
14
15 2 our $DEBUG = 0;
16
17 sub import {
18 2 ▶ my($class,%args) = @_;
Subroutine import: called CC=3 SCAR=14.8
19 2 ▶ return unless exists $args{'autotie'};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $args{"autotie"} 2 0 2
20 0 ▶ $args{'filehandle'} = $args{'autotie'} =~ /::/ ? $args{'autotie'} : caller().'::'.$args{'autotie'};
Branch: 1 branch
BranchTrueFalseTotal
$args{'autotie'} =~ /::/ ? : 0 0 0
21 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
22 0 my $self = tie(*{$args{'filehandle'}},$class,%args);
23 0 return $self;
24 }
25
26 2 my($gmt,$loc,$lmod);
27
28 # NOTE: check for escaped \( or \), what should it do?
29 2 our $L; # used to return the brackets count
30 our $RE_parens_2C = qr/
31 ( # g1, everything inside the brackets, incl brackets
32 \(
33 ( (?: # g2, everything inside the brackets
34 (?{ $L = 1 }) # $L counts ('s inside pattern
35 (?:
36 (?:"[^"\\]* (?: \\.[^"\\]* )* ")
37 | (?:'[^'\\]* (?: \\.[^'\\]* )* ')
38 | (?:`[^`\\]* (?: \\.[^`\\]* )* `)
39 | (?:[^"'`)(])
40 | (?: \(
41 (?{ local $L=$L+1; }) # new set of nested parens
42 )
43 | (?: \)
44 (?{ local $L=$L-1; }) # close a set of nested parens
45 (?(?{ $L==0 })(?!)) # ...if there was no matching open paren...
46 )
47 )*
48 )* ) # end g2
49 \)
50 ) # end g1
51 2 /x;
52
53 2 our $RE_quote_dbl_NC = qr/(?:"[^"\\]* (?: \\.[^"\\]* )* ")/x;
54 2 our $RE_quote_single_NC = qr/(?:'[^'\\]* (?: \\.[^'\\]* )* ')/x;
55 2 our $RE_quote_backtick_NC = qr/(?:`[^`\\]* (?: \\.[^`\\]* )* `)/x;
56 2 our $RE_all_quote_NC = qr/$RE_quote_dbl_NC|$RE_quote_single_NC|$RE_quote_backtick_NC/;
57 2 our $RE_all_no_quote_NC = qr/$RE_all_quote_NC|[^'"`]/;
58 2 our $RE_all_no_paren_NC = qr/$RE_all_quote_NC|[^()'"`]/;
59 2 our $RE_all_no_paren_noop_NC = qr/$RE_all_quote_NC | [^()'"`&\|] | &[^&] | \|[^\|]/x;
60 2 our $RE_single_quote_false_NC = qr/^ (?:\s*'')+\s* [']* $
61 |^ '? (?:\\')* $/x;
62 # empty, or 1+ unspaced single quotes, trivially false
63 # pairs of empty single quotes, false
64 # alternating backslash-single quotes, false
65
66
67 # apache's own, special way of quoting strings
68 2 our $RE_apache_expr_quote = qr/ (?:"(?:[^"\\]|[\\]+[^\\])*?")
69 |(?:'(?:[^'\\]|[\\]+[^\\])*?')
70 |(?:`(?:[^`\\]|[\\]+[^\\])*?`)
71 /x;
72
73 # NOTE: quotes that would be openers which are immediately preceeded by \w are treated as \w
74 # NOTE: needs to be preceeded by \s or =, otherwise becomes part of token (parsing oddity with apache 2.2.22)
75 2 our $RE_apache_expr_quote_all = qr/ $RE_apache_expr_quote | [^'"`\s]/x;
76 2 our $RE_runaway = qr/ \s+ \w+['"`]\S*\s+[^'"`]+['"`]+ /x;
77 2 our $RE_token_NC = qr{[[:alpha:]]\S+? (?:\s+ $RE_apache_expr_quote_all*? )*? $RE_runaway? }x;
78
79
80 sub new {
81 18 ▶ my($class,%args) = @_;
Subroutine new: called CC=13 SCAR=26.5
Pod documented
82 18 my $self = bless {}, $class;
83
84 18 $self->{'_handle'} = undef;
85 18 my $script_name = '';
86 18 ▶ if(exists $ENV{'SCRIPT_NAME'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $ENV{"SCRIPT_NAME"}) 0 18 18
87 0 ($script_name) = $ENV{'SCRIPT_NAME'} =~ /([^\/]+)$/;
88 }
89
90 18 tie $gmt, 'CGI::apacheSSI::Gmt', $self;
91 18 tie $loc, 'CGI::apacheSSI::Local', $self;
92 18 tie $lmod, 'CGI::apacheSSI::LMOD', $self;
93
94 18 ▶ $ENV{'DOCUMENT_ROOT'} ||= '';
Condition50%1/2
$ENV{"DOCUMENT_ROOT"} ||= ""
l!l
018
MC/DC0%0/1
$ENV{"DOCUMENT_ROOT"} ||= ""
$ENV{"DOCUMENT_ROOT"}
Truth table50%1/2
A
A= $ENV{"DOCUMENT_ROOT"}
Aresult
11
00
95 $self->{'_variables'} = {
96 DOCUMENT_URI => ($args{'DOCUMENT_URI'} || $ENV{'SCRIPT_NAME'}),
97 DATE_GMT => $gmt,
98 DATE_LOCAL => $loc,
99 LAST_MODIFIED => $lmod,
100 DOCUMENT_NAME => ($args{'DOCUMENT_NAME'} || $script_name),
101 18 ▶ DOCUMENT_ROOT => ($args{'DOCUMENT_ROOT'} || $ENV{DOCUMENT_ROOT}),
Condition66%6/9
$args{'DOCUMENT_URI'} || $ENV{'SCRIPT_NAME'}
l!l&&r!l&&!r
1017
$args{'DOCUMENT_NAME'} || $script_name
l!l&&r!l&&!r
1017
$args{'DOCUMENT_ROOT'} || $ENV{'DOCUMENT_ROOT'}
l!l&&r!l&&!r
2016
MC/DC50%1/2
$args{'DOCUMENT_URI'} || $ENV{'SCRIPT_NAME'}
$args{'DOCUMENT_URI'} $ENV{'SCRIPT_NAME'}
MC/DC50%1/2
$args{'DOCUMENT_NAME'} || $script_name
$args{'DOCUMENT_NAME'} $script_name
MC/DC50%1/2
$args{'DOCUMENT_ROOT'} || $ENV{'DOCUMENT_ROOT'}
$args{'DOCUMENT_ROOT'} $ENV{'DOCUMENT_ROOT'}
Truth table66%2/3
A || B
A= $args{'DOCUMENT_URI'}B= $ENV{'SCRIPT_NAME'}
ABresult
1X1
011
000
Truth table66%2/3
A || B
A= $args{'DOCUMENT_NAME'}B= $script_name
ABresult
1X1
011
000
Truth table66%2/3
A || B
A= $args{'DOCUMENT_ROOT'}B= $ENV{'DOCUMENT_ROOT'}
ABresult
1X1
011
000
102 };
103
104 $self->{'_config'} = { # NOTE: TODO: get these from apache config
105 errmsg => ($args{'errmsg'} || '[an error occurred while processing this directive]'),
106 sizefmt => ($args{'sizefmt'} || 'abbrev'),
107 timefmt => ($args{'timefmt'} || undef),
108 SSIUndefinedEcho => ($args{'SSIUndefinedEcho'} || '(none)'),
109 18 ▶ _verbose_errors => ($args{'_verbose_errors'} || 0) # NOTE: TODO: document this option
Condition80%8/10
$args{'errmsg'} || '[an error occurred while processing this directive]'
l!l
117
$args{'sizefmt'} || 'abbrev'
l!l
117
$args{'timefmt'} || undef
l!l
216
$args{'SSIUndefinedEcho'} || '(none)'
l!l
018
$args{'_verbose_errors'} || 0
l!l
018
MC/DC100%1/1
$args{'errmsg'} || '[an error occurred while processing this directive]'
$args{'errmsg'}
MC/DC100%1/1
$args{'sizefmt'} || 'abbrev'
$args{'sizefmt'}
MC/DC100%1/1
$args{'timefmt'} || undef
$args{'timefmt'}
MC/DC0%0/1
$args{'SSIUndefinedEcho'} || '(none)'
$args{'SSIUndefinedEcho'}
MC/DC0%0/1
$args{'_verbose_errors'} || 0
$args{'_verbose_errors'}
Truth table100%2/2
A
A= $args{'errmsg'}
Aresult
11
00
Truth table100%2/2
A
A= $args{'sizefmt'}
Aresult
11
00
Truth table100%2/2
A
A= $args{'timefmt'}
Aresult
11
00
Truth table50%1/2
A
A= $args{'SSIUndefinedEcho'}
Aresult
11
00
Truth table50%1/2
A
A= $args{'_verbose_errors'}
Aresult
11
00
110 };
111
112 18 ▶ $self->{_max_recursions} = $args{MAX_RECURSIONS} || 100; # no "infinite" loops
Condition100%2/2
$args{'MAX_RECURSIONS'} || 100
l!l
117
MC/DC100%1/1
$args{'MAX_RECURSIONS'} || 100
$args{'MAX_RECURSIONS'}
Truth table100%2/2
A
A= $args{'MAX_RECURSIONS'}
Aresult
11
00
113 18 $self->{_recursions} = {};
114
115 18 ▶ $self->{_cookie_jar} = $args{COOKIE_JAR} || HTTP::Cookies->new();
Condition66%2/3
$args{'COOKIE_JAR'} || 'HTTP::Cookies'->new
l!l&&r!l&&!r
1170
MC/DC0%0/2
$args{'COOKIE_JAR'} || 'HTTP::Cookies'->new
$args{'COOKIE_JAR'} 'HTTP::Cookies'->new
Truth table66%2/3
A || B
A= $args{'COOKIE_JAR'}B= 'HTTP::Cookies'->new
ABresult
1X1
011
000
116
117 18 $self->{'_in_if'} = 0;
118 18 $self->{'_suspend'} = [0];
119 18 $self->{'_seen_true'} = [1];
120
121 18 return $self;
122 }
123
124 sub TIEHANDLE {
125 1 ▶ my($class,%args) = @_;
Subroutine TIEHANDLE: called CC=3 SCAR=11.3
126 1 my $self = $class->new(%args);
127 1 $self->{'_handle'} = do { local *STDOUT };
128 1 my $handle_to_tie = '';
129 1 ▶ if($args{'filehandle'} !~ /::/) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $args{'filehandle'} =~ /::/) { } 1 0 1
130 1 $handle_to_tie = caller().'::'.$args{'filehandle'};
131 } else {
132 0 $handle_to_tie = $args{'filehandle'};
133 }
134 1 ▶ open($self->{'_handle'},'>&'.$handle_to_tie) or die "Failed to copy the filehandle ($handle_to_tie): $!";
Branch: 1 branch
BranchTrueFalseTotal
open $self->{"_handle"}, '>&' . $handle_to_tie or die "Failed to copy the filehandle ($handle_to_tie): $!" 0 1 1
135 1 return $self;
136 }
137
138 sub PRINT {
139 2 ▶ my $self = shift;
Subroutine PRINT: called CC=1 SCAR=0.0
140 2 print {$self->{'_handle'}} map { $self->process($_) } @_;
141 }
142
143 sub PRINTF {
144 0 ▶ my $self = shift;
Subroutine PRINTF: not called CC=1 SCAR=6.9
145 0 my $fmt = shift;
146 0 printf {$self->{'_handle'}} $fmt, map { $self->process($_) } @_;
147 }
148
149 sub CLOSE {
150 1 ▶ my($self) = @_;
Subroutine CLOSE: called CC=1 SCAR=0.0
151 1 close $self->{'_handle'};
152 }
153
154 sub SSI_WARN {
155 0 ▶ my($self,$msg) = @_;
Subroutine SSI_WARN: not called CC=1 SCAR=6.9
Pod undocumented
156 0 warn ref($self)." warn: $msg\n";
157 }
158
159 sub SSI_ERROR {
160 3 ▶ (my $self, $@) = @_;
Subroutine SSI_ERROR: called CC=1 SCAR=0.0
Pod undocumented
161 3 warn ref($self)." error: $@\n";
162 3 return; # returning false here allows us to do one line error returns.
163 }
164
165 sub SSI_ERROR_FLUSH {
166 3 ▶ my($self,$msg) = @_;
Subroutine SSI_ERROR_FLUSH: called CC=3 SCAR=11.2
Pod undocumented
167 3 ▶ if ($msg) {$self->SSI_ERROR($msg);}
Branch: 1 branch
BranchTrueFalseTotal
if ($msg) 3 0 3
168 3 $msg=$@; # NOTE: DEBUG ONLY!
169 3 undef $@;
170 3 ▶ return "[SSI ERROR=[$msg]]" if $self->{'_config'}->{'_verbose_errors'}; # NOTE: DEBUG ONLY!
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_config"}{"_verbose_errors"} 0 3 3
171 3 return $self->{'_config'}->{'errmsg'};
172 }
173
174
175
176
177 # NOTE: "if" allows expr="myexpr1" expr="myexpr2" where myexpr2 overwrites myexpr1.
178
179 sub process { # NOTE: -- FIXME -- this fails if we comment out the tokens.. ie <!-- <!--#if -->
180 # NOTE: -- FIXME -- this should fail if we have any open quotes (ie, the --> doesnt magically close the tag.. in apache 2.2 at least)
181 56 ▶ my($self,@shtml) = @_;
Subroutine process: called CC=4 SCAR=13.9
Pod undocumented
182 56 my $processed = '';
183
184 # NOTE: FIXME: would this be easier with a global replace s///ge ?
185 56 @shtml = split(m/(<!--\#$RE_token_NC-->)/sx, join '',@shtml); # this will slurp up anything inside quotes, single or double
186
187 56 my $count=0;
188 56 for my $token (@shtml) {
189 114 ▶ if($token =~ /^<!--\#($RE_token_NC)-->$/sx) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token =~ /^<!--\#($CGI::apacheSSI::RE_token_NC)-->$/sx) { } 54 60 114
190 54 $processed .= $self->_process_ssi_text($1);
191 } else {
192 60 ▶ next if $self->_suspended;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_suspended 0 60 60
193 60 $processed .= $token;
194 }
195 }
196 56 return $processed;
197 }
198
199
200
201 sub _process_ssi_text {
202 54 ▶ my($self,$text) = @_;
Subroutine _process_ssi_text: called CC=6 SCAR=21.4
203
204 # what's the first \S+?
205 54 ▶ if($text !~ s/^(\S+)\s*//)
Branch: 1 branch
BranchTrueFalseTotal
unless ($text =~ s/^(\S+)\s*//) 0 54 54
206 0 { return $self->SSI_ERROR_FLUSH("failed to find method name at beginning of string: '$text'."); }
207
208 54 my $method = $1;
209 54 ▶ if (! $self->can($method) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->can($method)) 0 54 54
210 0 { return $self->SSI_ERROR_FLUSH("unknown directive \"$method\" in parsed doc."); }
211
212 # are we suspended?
213 54 ▶ return '' if($self->_suspended and $method !~ /^(?:if|else|elif|endif)\b/);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_suspended and not $method =~ /^(?:if|else|elif|endif)\b/ 0 54 54
Condition33%1/3
$self->_suspended and not $method =~ /^(?:if|else|elif|endif)\b/
!ll&&!rl&&r
5400
MC/DC0%0/2
$self->_suspended and not $method =~ /^(?:if|else|elif|endif)\b/
$self->_suspended not $method =~ /^(?:if|else|elif|endif)\b/
Truth table33%1/3
A and not(B)
A= $self->_suspendedB= not $method =~ /^(?:if|else|elif|endif)\b/
ABresult
0X0
100
111
214
215 54 my $res = $self->$method( $self->parse_args($text, $method) );
216 54 ▶ if ($@) { return $self->SSI_ERROR_FLUSH();}
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 54 54
217 54 return $res;
218 }
219
220
221
222 # many thanks to HTML::SimpleParse, with a couple of modifications
223 sub parse_args {
224 54 ▶ my ($self, $str, $method) = @_;
Subroutine parse_args: called CC=10 SCAR=30.0
Pod undocumented
225 54 my @returns;
226
227 # Make sure we start searching at the beginning of the string
228 54 pos($str) = 0;
229
230 54 while (1) {
231 110 ▶ next if $str =~ m/\G\s+/gc; # Get rid of leading whitespace
Branch: 1 branch
BranchTrueFalseTotal
if $str =~ /\G\s+/cg 0 110 110
232
233 110 ▶ if ( $str =~ m/\G
Branch: 2 branches
BranchTrueFalseTotal
if ($str =~ /\G ([\w.-]+)\s*=\s* # the key (?: # ($RE_all_quote_NC) \s* # anything in quotes ($CGI::apacheSSI::RE_apache_expr_quote_all) \s* # anything in quotes | # or ([^\s>]*) \s* # anything else, without whitespace or > )/cgx) { } 56 54 110
elsif ($str =~ m[\G/?([\w.-]+)\s*]cg) { } 0 54 54
234 ([\w.-]+)\s*=\s* # the key
235 (?:
236 # ($RE_all_quote_NC) \s* # anything in quotes
237 ($RE_apache_expr_quote_all) \s* # anything in quotes
238 | # or
239 ([^\s>]*) \s* # anything else, without whitespace or >
240 )/gcx ) {
241 56 my ($key, $val) = ($1, $+);
242 # ----- NOTE: if $key is not "expr" trim the quotes..
243 # ----- (apache evaluates differently depending on the type of quotes)
244 56 ▶ if ($key ne "expr") {$val =~ s/^['"`]?(.*?)['"`]?$/$1/;}
Branch: 1 branch
BranchTrueFalseTotal
if ($key ne "expr") 56 0 56
245 56 push @returns, $key, $val;
246 } elsif ( $str =~ m,\G/?([\w.-]+)\s*,gc ) {
247 0 push @returns, $1 , undef;
248 } else {
249 54 ▶ if ($str =~ m/\G(.+)/gc) # anything left over??
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ /\G(.+)/cg) 0 54 54
250 {
251 0 $self->SSI_ERROR("missing argument name for value to tag \"$method\" in");
252 # NOTE: notice this is NOT a "return".. we want processing to continue normally
253 }
254 54 last;
255 }
256 }
257
258 # too many arguments for if element in
259 # else/endif/printenv directive does not take tags in
260 54 my %allowed_tag_count; # NOTE: this needs to be moved up
261 54 $allowed_tag_count{'if'}=["expr"];
262 54 $allowed_tag_count{'else'}=[];
263
264 54 ▶ if (defined $allowed_tag_count{$method})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $allowed_tag_count{$method}) 0 54 54
265 {
266 0 ▶ if (@returns > 2 * @{ $allowed_tag_count{$method} })
Branch: 2 branches
BranchTrueFalseTotal
if (@returns > 2 * @{$allowed_tag_count{$method};}) { } 0 0 0
elsif (@returns < 2 * @{$allowed_tag_count{$method};}) { } 0 0 0
267 {
268 0 ▶ if (@{ $allowed_tag_count{$method} } == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (@{$allowed_tag_count{$method};} == 0) { } 0 0 0
269 0 { $self->SSI_ERROR("\"$method\" directive does not take tags in");}
270 else
271 0 { $self->SSI_ERROR("too many arguments for \"$method\" element in");}
272 }
273 0 elsif (@returns < 2 * @{ $allowed_tag_count{$method} })
274 0 { $self->SSI_ERROR("missing arguments for directive \"$method\"");} # NOTE: fix this error message
275 }
276
277 54 return @returns;
278 }
279
280
281 sub _interp_vars {
282 6 ▶ local $^W = 0;
Subroutine _interp_vars: called CC=6 SCAR=33.3
283 6 my($self,$text,$setcmd) = @_;
284
285 # NOTE: var name in ${} MUST start with at least one \w
286 6 $text =~ s{ ((\\*) ((\\)|(\$)) (\{)?(\w (?(6)(.*)\}|(\w*)) )) }
287 {
288 0 my ($all,$slashes, $slash,$dollar, $lbrak,$var)=($1,$2, $4,$5, $6,$7);
289 0 $slashes .= $slash; # NOTE: this can be improved
290 0 ▶ if ($lbrak) {chop $var};
Branch: 1 branch
BranchTrueFalseTotal
if ($lbrak) 0 0 0
291
292 0 ▶ if (! $setcmd)
Branch: 1 branch
BranchTrueFalseTotal
unless ($setcmd) 0 0 0
293 0 { chop($slashes); }
294
295 0 ▶ if ($dollar && ! $slashes)
Branch: 1 branch
BranchTrueFalseTotal
if ($dollar and not $slashes) { } 0 0 0
Condition0%0/3
$dollar and not $slashes
!ll&&!rl&&r
000
MC/DC0%0/2
$dollar and not $slashes
$dollar not $slashes
Truth table0%0/3
A and not(B)
A= $dollarB= not $slashes
ABresult
0X0
100
111
296 0 { $var = $self->_echo($var); }
297 else
298 {
299 0 ▶ $var = "{$var}" if ($lbrak) ;
Branch: 1 branch
BranchTrueFalseTotal
if $lbrak 0 0 0
300 0 $var = $dollar.$var;
301 }
302 0 $slashes.$var
303 }exg;
304
305 6 return $text;
306 }
307
308
309
310 # for internal use only - returns the thing passed in if it's not defined. echo() returns '' in that case.
311 sub _echo {
312 0 ▶ my($self,$key,$var) = @_;
Subroutine _echo: not called CC=7 SCAR=40.3
313 0 ▶ $var = $key if @_ == 2;
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 2 0 0 0
314
315 0 ▶ if($var eq 'DATE_LOCAL') {
Branch: 3 branches
BranchTrueFalseTotal
if ($var eq 'DATE_LOCAL') { } 0 0 0
elsif ($var eq 'DATE_GMT') { } 0 0 0
elsif ($var eq 'LAST_MODIFIED') { } 0 0 0
316 0 return $loc;
317 } elsif($var eq 'DATE_GMT') {
318 0 return $gmt;
319 } elsif($var eq 'LAST_MODIFIED') {
320 0 return $lmod;
321 }
322
323 0 ▶ return $self->{'_variables'}->{$var} if exists $self->{'_variables'}->{$var};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"_variables"}{$var} 0 0 0
324 0 ▶ return $ENV{$var} if exists $ENV{$var};
Branch: 1 branch
BranchTrueFalseTotal
if exists $ENV{$var} 0 0 0
325 0 return '';
326 }
327
328 #
329 # ssi directive methods
330 #
331
332 sub config {
333 5 ▶ my($self,$type,$value) = @_;
Subroutine config: called CC=7 SCAR=23.0
Pod documented
334 5 ▶ if($type =~ /^timefmt$/i) {
Branch: 4 branches
BranchTrueFalseTotal
if ($type =~ /^timefmt$/i) { } 3 2 5
elsif ($type =~ /^sizefmt$/i) { } 1 1 2
elsif ($type =~ /^errmsg$/i) { } 1 0 1
elsif ($type =~ /^_verbose_errors/i) { } 0 0 0
335 3 $self->{'_config'}->{'timefmt'} = $value;
336 } elsif($type =~ /^sizefmt$/i) {
337 1 ▶ if(lc $value eq 'abbrev') {
Branch: 2 branches
BranchTrueFalseTotal
if (lc $value eq 'abbrev') { } 0 1 1
elsif (lc $value eq 'bytes') { } 1 0 1
338 0 $self->{'_config'}->{'sizefmt'} = 'abbrev';
339 } elsif(lc $value eq 'bytes') {
340 1 $self->{'_config'}->{'sizefmt'} = 'bytes';
341 } else {
342 0 return $self->SSI_ERROR_FLUSH("value for sizefmt is '$value'. It must be 'abbrev' or 'bytes'.");
343 }
344 } elsif($type =~ /^errmsg$/i) {
345 1 $self->{'_config'}->{'errmsg'} = $value;
346 } elsif($type =~ /^_verbose_errors/i) {
347 0 $self->{'_config'}->{'_verbose_errors'} = $value;
348 } else {
349 0 return $self->SSI_ERROR_FLUSH("arg to config is '$type'. It must be one of: 'timefmt', 'sizefmt', or 'errmsg'.");
350 }
351 5 return '';
352 }
353
354 sub set {
355 6 ▶ my($self,%args) = @_;
Subroutine set: called CC=2 SCAR=6.9
Pod documented
356 6 ▶ if(scalar keys %args > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %args > 1) { } 3 3 6
357 3 $self->{'_variables'}->{$args{'var'}} = $self->_interp_vars($args{'value'}, 1);
358 } else { # var => value notation
359 3 my($var,$value) = %args;
360 3 $self->{'_variables'}->{$var} = $self->_interp_vars($value, 1);
361 }
362 6 return '';
363 }
364
365 sub escaped {
366 9 ▶ my ($t)=@_;
Subroutine escaped: called CC=1 SCAR=0.0
Pod undocumented
367 9 $t =~ s/\\\$/\$/g;
368 9 return $t ;
369 }
370
371 sub echo {
372 12 ▶ my($self,$key,$var) = @_;
Subroutine echo: called CC=9 SCAR=27.5
Pod documented
373 12 ▶ $var = $key if @_ == 2;
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 2 7 5 12
374 12 my $encoding;
375 12 ▶ if ($key eq 'encoding') {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "encoding") 0 12 12
376 0 $encoding = $var; # NOTE: TODO: handle encoding.
377 0 ($key,$var) = @_[3,4];
378 0 ▶ $var = $key if (!$var);
Branch: 1 branch
BranchTrueFalseTotal
unless $var 0 0 0
379 }
380
381 12 ▶ if($var eq 'DATE_LOCAL') {
Branch: 3 branches
BranchTrueFalseTotal
if ($var eq 'DATE_LOCAL') { } 1 11 12
elsif ($var eq 'DATE_GMT') { } 0 11 11
elsif ($var eq 'LAST_MODIFIED') { } 2 9 11
382 1 return $loc;
383 } elsif($var eq 'DATE_GMT') {
384 0 return $gmt;
385 } elsif($var eq 'LAST_MODIFIED') {
386 2 return $lmod;
387 }
388 # it seems apache's "echo" command escapes out instances of "\$" to display just "$"
389 9 ▶ return &escaped($self->{'_variables'}->{$var}) if exists $self->{'_variables'}->{$var};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"_variables"}{$var} 9 0 9
390 0 ▶ return &escaped($ENV{$var}) if exists $ENV{$var};
Branch: 1 branch
BranchTrueFalseTotal
if exists $ENV{$var} 0 0 0
391 0 return $self->{'_config'}->{'SSIUndefinedEcho'};
392 }
393
394 sub printenv {
395 0 ▶ return join "\n",map {"$_=$ENV{$_}"} keys %ENV;
Subroutine printenv: not called CC=1 SCAR=6.9
Pod documented
396 }
397
398 sub include {
399 45 ▶ $DEBUG and do { local $" = "','"; warn "DEBUG: include('@_')\n" };
Subroutine include: called CC=4 SCAR=15.5
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$CGI::apacheSSI::DEBUG and do { local $" = "','"; warn "DEBUG: include('@{_}')\n" } 0 45 45
400 45 my($self,$type,$filename) = @_;
401 45 ▶ if(lc $type eq 'file') {
Branch: 2 branches
BranchTrueFalseTotal
if (lc $type eq 'file') { } 42 3 45
elsif (lc $type eq 'virtual') { } 3 0 3
402 42 return $self->_include_file($filename);
403 } elsif(lc $type eq 'virtual') {
404 3 return $self->_include_virtual($filename);
405 } else {
406 0 return $self->SSI_ERROR_FLUSH("arg to include is '$type'. It must be one of: 'file' or 'virtual'.");
407 }
408 }
409
410 sub _include_file {
411 43 ▶ $DEBUG and do { local $" = "','"; warn "DEBUG: _include_file('@_')\n" };
Subroutine _include_file: called CC=5 SCAR=17.4
Branch: 1 branch
BranchTrueFalseTotal
$CGI::apacheSSI::DEBUG and do { local $" = "','"; warn "DEBUG: _include_file('@{_}')\n" } 0 43 43
412 43 my($self,$filename) = @_;
413
414 # get the filename to open
415 43 ▶ $filename = catfile($FindBin::Bin,$filename) unless -e $filename;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $filename 0 43 43
416
417 # if we've reached MAX_RECURSIONS for this filename, warn and return the error
418 43 ▶ if(++$self->{_recursions}->{$filename} >= $self->{_max_recursions}) {
Branch: 1 branch
BranchTrueFalseTotal
if (++$self->{"_recursions"}{$filename} >= $self->{"_max_recursions"}) 1 42 43
419 1 return $self->SSI_ERROR_FLUSH("the maximum number of 'include file' recursions has been exceeded for '$filename'.");
420 }
421
422 # open the file, or warn and return an error
423 42 my $fh = do { local *STDIN };
424 42 ▶ open($fh,$filename) or do {
Branch: 1 branch
BranchTrueFalseTotal
open $fh, $filename or do { return $self->SSI_ERROR_FLUSH("failed to open file ($filename): $!") } 0 42 42
425 0 return $self->SSI_ERROR_FLUSH("failed to open file ($filename): $!");
426 };
427
428 # process the included file and return the result
429 42 return $self->process(join '',<$fh>);
430 }
431
432 sub _include_virtual {
433 3 ▶ $DEBUG and do { local $" = "','"; warn "DEBUG: _include_virtual('@_')\n" };
Subroutine _include_virtual: called CC=17 SCAR=36.8
Branch: 1 branch
BranchTrueFalseTotal
$CGI::apacheSSI::DEBUG and do { local $" = "','"; warn "DEBUG: _include_virtual('@{_}')\n" } 0 3 3
434 3 my($self,$filename) = @_;
435
436 # if this is a local file that we can just read, let's do that instead of getting it virtually
437 3 ▶ if($filename =~ m|^/(.+)|) { # could be on the local server: absolute filename, relative to ., relative to $ENV{DOCUMENT_ROOT}
Branch: 1 branch
BranchTrueFalseTotal
if ($filename =~ m[^/(.+)]) 1 2 3
438 1 my $file = $1;
439 1 ▶ if(-e '/'.$file) { # back to the original
Branch: 3 branches
BranchTrueFalseTotal
if (-e '/' . $file) { } 0 1 1
elsif (-e catfile($self->{'_variables'}{'DOCUMENT_ROOT'}, $file)) { } 1 0 1
elsif (-e catfile($FindBin::Bin, $file)) { } 0 0 0
440 0 $file = '/'.$file;
441 } elsif(-e catfile($self->{'_variables'}->{'DOCUMENT_ROOT'},$file)) {
442 1 $file = catfile($self->{'_variables'}->{'DOCUMENT_ROOT'},$file);
443 } elsif(-e catfile($FindBin::Bin,$file)) {
444 # $file = atfile($FindBin::Bin,$file); # <----- NOTE: is this a typo here??
445 0 $file = catfile($FindBin::Bin,$file); # fixing it just in case
446 }
447 1 ▶ return $self->_include_file($file) if -e $file;
Branch: 1 branch
BranchTrueFalseTotal
if -e $file 1 0 1
448 }
449
450 # create the URI to get(), or warn and return the error
451 my $uri = eval {
452 2 my $uri = URI->new($filename);
453 2 ▶ $uri->scheme($uri->scheme || ($ENV{HTTPS} ? 'https' : 'http')); # ??
Branch: 1 branch
BranchTrueFalseTotal
$ENV{'HTTPS'} ? : 0 0 0
Condition33%1/3
$uri->scheme || ($ENV{'HTTPS'} ? 'https' : 'http')
l!l&&r!l&&!r
200
MC/DC0%0/2
$uri->scheme || ($ENV{'HTTPS'} ? 'https' : 'http')
$uri->scheme ($ENV{'HTTPS'} ? 'https' : 'http')
Truth table33%1/3
A || B
A= $uri->schemeB= ($ENV{'HTTPS'} ? 'https' : 'http')
ABresult
1X1
011
000
454 2 ▶ $uri->host($uri->host || $ENV{'HTTP_HOST'} || $ENV{'SERVER_NAME'} || 'localhost');
Condition37%3/8
$uri->host || $ENV{'HTTP_HOST'} || $ENV{'SERVER_NAME'} || 'localhost'
l!l
20
$uri->host or $ENV{"HTTP_HOST"} or $ENV{"SERVER_NAME"}
l!l&&r!l&&!r
200
$uri->host or $ENV{"HTTP_HOST"}
l!l&&r!l&&!r
200
MC/DC0%0/3
$uri->host || $ENV{'HTTP_HOST'} || $ENV{'SERVER_NAME'} || 'localhost'
$uri->host $ENV{"HTTP_HOST"} $ENV{"SERVER_NAME"}
Truth table25%1/4
A or B or C
A= $uri->hostB= $ENV{"HTTP_HOST"}C= $ENV{"SERVER_NAME"}
ABCresult
1XX1
01X1
0011
0000
455 2 $uri;
456 2 ▶ } or do {
Branch: 1 branch
BranchTrueFalseTotal
my $uri = eval { do { my $uri = "URI"->new($filename); $uri->scheme($uri->scheme || ($ENV{"HTTPS"} ? "https" : "http")); $uri->host($uri->host || $ENV{"HTTP_HOST"} || $ENV{"SERVER_NAME"} || "localhost"); $uri } } or do { return $self->SSI_ERROR_FLUSH("failed to create a URI based on '${filename}'.") } 0 2 2
457 0 return $self->SSI_ERROR_FLUSH("failed to create a URI based on '$filename'.");
458 };
459 2 ▶ if($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 2 2
460 0 return $self->SSI_ERROR_FLUSH("failed to create a URI based on '$filename'.");
461 }
462
463 # get the content of the request
464 2 ▶ $self->{_ua} ||= $self->_get_ua();
Condition33%1/3
$self->{"_ua"} ||= $self->_get_ua
l!l&&r!l&&!r
020
MC/DC0%0/2
$self->{"_ua"} ||= $self->_get_ua
$self->{"_ua"} $self->_get_ua
Truth table33%1/3
A ||= B
A= $self->{"_ua"}B= $self->_get_ua
ABresult
1X1
011
000
465 2 my $url = $uri->canonical;
466
467 # have we reached MAX_RECURSIONS?
468 2 ▶ if(++$self->{_recursions}->{$url} >= $self->{_max_recursions}) {
Branch: 1 branch
BranchTrueFalseTotal
if (++$self->{"_recursions"}{$url} >= $self->{"_max_recursions"}) 0 2 2
469 0 return $self->SSI_ERROR_FLUSH("the maximum number of 'include virtual' recursions has been exceeded for '$url'.");
470 }
471
472 2 my $response = $self->{_ua}->get($url);
473
474 # is it a success?
475 2 ▶ unless($response->is_success) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($response->is_success) 1 1 2
476 1 return $self->SSI_ERROR_FLUSH("failed to get('$url'): ".$response->status_line.".");
477 }
478 # process the included content and return the result
479 1 return $self->process($response->content);
480 }
481
482 sub _get_ua {
483 3 ▶ my $self = shift;
Subroutine _get_ua: called CC=2 SCAR=7.0
484 3 my %conf = ();
485 3 ▶ $conf{agent} = $ENV{HTTP_USER_AGENT} if $ENV{HTTP_USER_AGENT};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"HTTP_USER_AGENT"} 0 3 3
486 3 my $ua = LWP::UserAgent->new(%conf);
487 3 $ua->cookie_jar($self->{_cookie_jar});
488 3 return $ua;
489 }
490
491 sub cookie_jar {
492 0 ▶ my $self = shift;
Subroutine cookie_jar: not called CC=2 SCAR=17.9
Pod documented
493 0 ▶ if(my $jar = shift) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $jar = shift()) 0 0 0
494 0 $self->{_cookie_jar} = $jar;
495 }
496 0 return $self->{_cookie_jar};
497 }
498
499 sub exec {
500 2 ▶ my($self,$type,$filename) = @_;
Subroutine exec: called CC=3 SCAR=11.3
Pod documented
501 2 ▶ if(lc $type eq 'cmd') {
Branch: 2 branches
BranchTrueFalseTotal
if (lc $type eq 'cmd') { } 1 1 2
elsif (lc $type eq 'cgi') { } 1 0 1
502 1 return $self->_exec_cmd($filename);
503 } elsif(lc $type eq 'cgi') {
504 1 return $self->_exec_cgi($filename);
505 } else {
506 0 return $self->SSI_ERROR_FLUSH("arg to exec() is '$type'. It must be one of: 'cmd' or 'cgi'.");
507 }
508 }
509
510 sub _exec_cmd {
511 1 ▶ my($self,$filename) = @_;
Subroutine _exec_cmd: called CC=3 SCAR=12.3
512
513 # have we reached MAX_RECURSIONS?
514 1 ▶ if(++$self->{_recursions}->{$filename} >= $self->{_max_recursions}) {
Branch: 1 branch
BranchTrueFalseTotal
if (++$self->{"_recursions"}{$filename} >= $self->{"_max_recursions"}) 0 1 1
515 0 return $self->SSI_ERROR_FLUSH("the maximum number of 'exec cmd' recursions has been exceeded for '$filename'.");
516 }
517
518 1 my $output = `$filename`; # security here is mighty bad.
519
520 # was the command a success?
521 1 ▶ if($?) {
Branch: 1 branch
BranchTrueFalseTotal
if ($?) 0 1 1
522 0 return $self->SSI_ERROR_FLUSH("`$filename` was not successful.");
523 }
524
525 # process the output, and return the result
526 1 return $self->process($output);
527 }
528
529 sub _exec_cgi { # no relative $filename allowed.
530 1 ▶ my($self,$filename) = @_;
Subroutine _exec_cgi: called CC=11 SCAR=31.4
531
532 # have we reached MAX_RECURSIONS?
533 1 ▶ if(++$self->{_recursions}->{$filename} >= $self->{_max_recursions}) {
Branch: 1 branch
BranchTrueFalseTotal
if (++$self->{"_recursions"}{$filename} >= $self->{"_max_recursions"}) 0 1 1
534 0 return $self->SSI_ERROR_FLUSH("the maximum number of 'exec cgi' recursions has been exceeded for '$filename'.");
535 }
536
537 # create the URI from the filename
538 my $uri = eval {
539 1 my $uri = URI->new($filename);
540 1 ▶ $uri->scheme($uri->scheme || ($ENV{HTTPS} ? 'https' : 'http')); # ??
Branch: 1 branch
BranchTrueFalseTotal
$ENV{'HTTPS'} ? : 0 0 0
Condition33%1/3
$uri->scheme || ($ENV{'HTTPS'} ? 'https' : 'http')
l!l&&r!l&&!r
100
MC/DC0%0/2
$uri->scheme || ($ENV{'HTTPS'} ? 'https' : 'http')
$uri->scheme ($ENV{'HTTPS'} ? 'https' : 'http')
Truth table33%1/3
A || B
A= $uri->schemeB= ($ENV{'HTTPS'} ? 'https' : 'http')
ABresult
1X1
011
000
541 1 ▶ $uri->host($uri->host || $ENV{'HTTP_HOST'} || $ENV{'SERVER_NAME'});
Condition33%2/6
$uri->host || $ENV{'HTTP_HOST'} || $ENV{'SERVER_NAME'}
l!l&&r!l&&!r
100
$uri->host or $ENV{"HTTP_HOST"}
l!l&&r!l&&!r
100
MC/DC0%0/3
$uri->host || $ENV{'HTTP_HOST'} || $ENV{'SERVER_NAME'}
$uri->host $ENV{"HTTP_HOST"} $ENV{'SERVER_NAME'}
Truth table25%1/4
A or B || C
A= $uri->hostB= $ENV{"HTTP_HOST"}C= $ENV{'SERVER_NAME'}
ABCresult
1XX1
01X1
0011
0000
542 1 ▶ $uri->query($uri->query || $ENV{'QUERY_STRING'});
Condition33%1/3
$uri->query || $ENV{'QUERY_STRING'}
l!l&&r!l&&!r
001
MC/DC0%0/2
$uri->query || $ENV{'QUERY_STRING'}
$uri->query $ENV{'QUERY_STRING'}
Truth table33%1/3
A || B
A= $uri->queryB= $ENV{'QUERY_STRING'}
ABresult
1X1
011
000
543 1 $uri;
544 1 ▶ } or do {
Branch: 1 branch
BranchTrueFalseTotal
my $uri = eval { do { my $uri = "URI"->new($filename); $uri->scheme($uri->scheme || ($ENV{"HTTPS"} ? "https" : "http")); $uri->host($uri->host || $ENV{"HTTP_HOST"} || $ENV{"SERVER_NAME"}); $uri->query($uri->query || $ENV{"QUERY_STRING"}); $uri } } or do { return $self->SSI_ERROR_FLUSH("failed to create a URI from '${filename}'.") } 0 1 1
545 0 return $self->SSI_ERROR_FLUSH("failed to create a URI from '$filename'.");
546 };
547 1 ▶ if($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 1 1
548 0 return $self->SSI_ERROR_FLUSH("failed to create a URI from '$filename'.");
549 }
550
551 # get the content
552 1 ▶ $self->{_ua} ||= $self->_get_ua();
Condition33%1/3
$self->{"_ua"} ||= $self->_get_ua
l!l&&r!l&&!r
010
MC/DC0%0/2
$self->{"_ua"} ||= $self->_get_ua
$self->{"_ua"} $self->_get_ua
Truth table33%1/3
A ||= B
A= $self->{"_ua"}B= $self->_get_ua
ABresult
1X1
011
000
553 1 my $url = $uri->canonical;
554 1 my $response = $self->{_ua}->get($url);
555
556 # success?
557 1 ▶ unless($response->is_success) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($response->is_success) 0 1 1
558 0 return $self->SSI_ERROR_FLUSH("failed to get('$filename').");
559 }
560
561 # process the content and return the result
562 1 return $self->process($response->content);
563 }
564
565 sub flastmod {
566 22 ▶ my($self,$type,$filename) = @_;
Subroutine flastmod: called CC=7 SCAR=20.5
Pod documented
567
568 22 ▶ if(lc $type eq 'file') {
Branch: 2 branches
BranchTrueFalseTotal
if (lc $type eq 'file') { } 21 1 22
elsif (lc $type eq 'virtual') { } 0 1 1
569 21 ▶ $filename = catfile($FindBin::Bin,$filename) unless -e $filename;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $filename 20 1 21
570 } elsif(lc $type eq 'virtual') {
571 0 ▶ $filename = catfile($self->{'_variables'}->{'DOCUMENT_ROOT'},$filename)
Branch: 1 branch
BranchTrueFalseTotal
unless $filename =~ /$self->{"_variables"}{"DOCUMENT_ROOT"}/ 0 0 0
572 unless $filename =~ /$self->{'_variables'}->{'DOCUMENT_ROOT'}/;
573 } else {
574 1 return $self->SSI_ERROR_FLUSH("the first argument to flastmod is '$type'. It must be one of: 'file' or 'virtual'.");
575 }
576
577 21 ▶ unless(-e $filename) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $filename) 0 21 21
578 0 return $self->SSI_ERROR_FLUSH("flastmod failed to find '$filename'.");
579 }
580
581 21 my $flastmod = (stat $filename)[9];
582
583 21 ▶ if($self->{'_config'}->{'timefmt'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'_config'}{'timefmt'}) { } 3 18 21
584 3 my @localtime = localtime($flastmod); # need this??
585 3 return Date::Format::strftime($self->{'_config'}->{'timefmt'},@localtime);
586 } else {
587 18 return scalar localtime($flastmod);
588 }
589 }
590
591 sub fsize {
592 1 ▶ my($self,$type,$filename) = @_;
Subroutine fsize: called CC=13 SCAR=41.7
Pod documented
593
594 1 ▶ if(lc $type eq 'file') {
Branch: 2 branches
BranchTrueFalseTotal
if (lc $type eq 'file') { } 1 0 1
elsif (lc $type eq 'virtual') { } 0 0 0
595 1 ▶ $filename = catfile($FindBin::Bin,$filename) unless -e $filename;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $filename 0 1 1
596 } elsif(lc $type eq 'virtual') {
597 0 ▶ $filename = catfile($ENV{'DOCUMENT_ROOT'},$filename) unless $filename =~ /$ENV{'DOCUMENT_ROOT'}/;
Branch: 1 branch
BranchTrueFalseTotal
unless $filename =~ /$ENV{"DOCUMENT_ROOT"}/ 0 0 0
598 } else {
599 0 return $self->SSI_ERROR_FLUSH("the first argument to fsize is '$type'. It must be one of: 'file' or 'virtual'.");
600 }
601 1 ▶ unless(-e $filename) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $filename) 0 1 1
602 0 return $self->SSI_ERROR_FLUSH("fsize failed to find '$filename'.");
603 }
604
605 1 my $fsize = (stat $filename)[7];
606
607 1 ▶ if(lc $self->{'_config'}->{'sizefmt'} eq 'bytes') {
Branch: 1 branch
BranchTrueFalseTotal
if (lc $self->{'_config'}{'sizefmt'} eq 'bytes') { } 1 0 1
608 1 ▶ 1 while $fsize =~ s/^(\d+)(\d{3})/$1,$2/g;
Branch: 1 branch
BranchTrueFalseTotal
$fsize =~ s/^(\d+)(\d{3})/$1,$2/g and do { '???' } 0 1 1
609 1 return $fsize;
610 } else { # abbrev
611 # gratefully lifted from Apache::SSI
612 0 ▶ return " 0k" unless $fsize;
Branch: 1 branch
BranchTrueFalseTotal
unless $fsize 0 0 0
613 0 ▶ return " 1k" if $fsize < 1024;
Branch: 1 branch
BranchTrueFalseTotal
if $fsize < 1024 0 0 0
614 0 ▶ return sprintf("%4dk", ($fsize + 512)/1024) if $fsize < 1048576;
Branch: 1 branch
BranchTrueFalseTotal
if $fsize < 1048576 0 0 0
615 0 ▶ return sprintf("%4.1fM", $fsize/1048576.0) if $fsize < 103809024;
Branch: 1 branch
BranchTrueFalseTotal
if $fsize < 103809024 0 0 0
616 0 ▶ return sprintf("%4dM", ($fsize + 524288)/1048576) if $fsize < 1048576;
Branch: 1 branch
BranchTrueFalseTotal
if $fsize < 1048576 0 0 0
617 }
618 }
619
620 #
621 # if/elsif/else/endif and related methods
622 #
623 # NOTE: anything calling _test should check $@
624 sub _test {
625 0 ▶ my($self,$test) = @_;
Subroutine _test: not called CC=50 SCAR=78.4
626 0 my $quote;
627 0 my ($pound, $pounds);
628
629 0 $test =~ s/^(['"`])\s*(.*?)\s*(\1)$/$2/; # trim off surrounding (matching) quotes, and whitespace
630 0 $quote= $1;
631
632 # trivial test returns:
633 0 ▶ return 0 if $test =~ /$RE_single_quote_false_NC/;
Branch: 1 branch
BranchTrueFalseTotal
if $test =~ /$CGI::apacheSSI::RE_single_quote_false_NC/ 0 0 0
634 0 ▶ return 1 if $test =~ /^["`]+$/; # 1+ double quotes or backticks, trivially true
Branch: 1 branch
BranchTrueFalseTotal
if $test =~ /^["`]+$/ 0 0 0
635 0 ▶ return 1 if $test =~ /^[\s`'"]*?([`'"])?[\s]+?\1$/; # whitespace inside second set of quotes, trivially true
Branch: 1 branch
BranchTrueFalseTotal
if $test =~ /^[\s`'"]*?([`'"])?[\s]+?\1$/ 0 0 0
636 0 ▶ return 1 if $test =~ /^[\w]+$/; # bareword (alphanum) trivially true
Branch: 1 branch
BranchTrueFalseTotal
if $test =~ /^[\w]+$/ 0 0 0
637
638 0 if (1) # ($test =~ m{^\(})
639 { # need to do this otherwise it creates infinite loop for some reason
640 0 ▶ if ($test =~ m{
Branch: 1 branch
BranchTrueFalseTotal
if ($test =~ / ((?:\!\s*)*) \s* # $1 ( # $2 $CGI::apacheSSI::RE_parens_2C # ($3, $4) has 2 capture groups | (?:$CGI::apacheSSI::RE_all_no_paren_noop_NC)* ) \s* (?: (\&\& | \|\| )? \s* # $5 (.*) # $6 )? \s* /x) { } 0 0 0
641 ((?:\!\s*)*) \s* # $1
642 ( # $2
643 $RE_parens_2C # ($3, $4) has 2 capture groups
644 |
645 (?:$RE_all_no_paren_noop_NC)*
646 ) \s*
647 (?:
648 (\&\& | \|\| )? \s* # $5
649 (.*) # $6
650 )? \s*
651 }x)
652 {
653 # $1 is pound, $4 is inside the brackets, $5 is the op, $6 is the RHS
654 0 my $LHS=$2;
655 0 my $LHS_parens=$4; # inside parentheses, does not include the parentheses
656 0 my $OP=$5;
657 0 my $RHS=$6;
658 # expr="x == '\\x'" is split into: LHS=[ x == ] RHS=[ '\\x' ]
659 0 $pounds=$pound=$1;
660 0 $pound=~s/(?:\!\s*\!\s*)*//; # remove even # of !s, as these cancel out
661
662 # if no op, and LHS and RHS, FAIL... because (x) b.. -- can be no LHS but RHS and noop
663 # if no op and no $RHS, return pound != test(LHS)
664 # if op, and no RHS or no LHS, FAIL
665 # if op, do op.. return [pound != test(LHS)] op [test(LHS)]
666 0 ▶ if ($OP) {
Branch: 1 branch
BranchTrueFalseTotal
if ($OP) { } 0 0 0
667 # LOGICAL COMPARISON && and ||
668 # NOTE: && and || have equal precedence
669
670 0 ▶ if ($LHS=~/^\s*$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($LHS =~ /^\s*$/) 0 0 0
671 0 return $self->SSI_ERROR("empty logical comparison in expr.");
672 }
673 0 ▶ if ($RHS=~/^\s*$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($RHS =~ /^\s*$/) 0 0 0
674 0 return $self->SSI_ERROR("empty logical comparison in expr.");
675 }
676
677 0 ▶ if ($LHS_parens) {$LHS = $LHS_parens;} # needs to be done here, because of empty comparison checker
Branch: 1 branch
BranchTrueFalseTotal
if ($LHS_parens) 0 0 0
678 0 $LHS = $self->_test($quote.$LHS.$quote);
679
680 0 ▶ if ($@) {return;} # there were errors in the test
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
681
682 0 ▶ if ($pound) {$LHS = !$LHS;}
Branch: 1 branch
BranchTrueFalseTotal
if ($pound) 0 0 0
683 0 $RHS = $quote.$RHS.$quote;
684
685 0 ▶ if ($OP eq "&&")
Branch: 1 branch
BranchTrueFalseTotal
if ($OP eq '&&') { } 0 0 0
686 0 ▶ { return ($LHS && $self->_test($RHS)); } # short circuits, faster
Condition0%0/3
$LHS && $self->_test($RHS)
!ll&&!rl&&r
000
MC/DC0%0/2
$LHS && $self->_test($RHS)
$LHS $self->_test($RHS)
Truth table0%0/3
A && B
A= $LHSB= $self->_test($RHS)
ABresult
0X0
100
111
687 else # ($OP eq "||")
688 0 ▶ { return ($LHS || $self->_test($RHS)); } # short circuits, faster
Condition0%0/3
$LHS || $self->_test($RHS)
l!l&&r!l&&!r
000
MC/DC0%0/2
$LHS || $self->_test($RHS)
$LHS $self->_test($RHS)
Truth table0%0/3
A || B
A= $LHSB= $self->_test($RHS)
ABresult
1X1
011
000
689 }
690 else {
691 # NO OP
692 0 ▶ if ($LHS && $RHS) {
Branch: 3 branches
BranchTrueFalseTotal
if ($LHS and $RHS) { } 0 0 0
elsif ($LHS) { } 0 0 0
elsif ($RHS) { } 0 0 0
Condition0%0/3
$LHS and $RHS
!ll&&!rl&&r
000
MC/DC0%0/2
$LHS and $RHS
$LHS $RHS
Truth table0%0/3
A and B
A= $LHSB= $RHS
ABresult
0X0
100
111
693 0 ▶ if ($LHS_parens) {
Branch: 1 branch
BranchTrueFalseTotal
if ($LHS_parens) 0 0 0
694 # return $self->SSI_ERROR("error in expression."); # NOTE: FIXME: improve this error msg..
695 # return $self->SSI_ERROR("error in expression. LHS and RHS but no OP"); # NOTE: FIXME: improve this error msg..
696 0 return $self->SSI_ERROR("error in expression. LHS [$LHS] and RHS [$RHS] but no OP"); # NOTE: FIXME: improve this error msg..
697 }
698 0 $test = $LHS.$RHS;
699 }
700 elsif ($LHS) # brackets or balanced quotes
701 {
702 0 ▶ if ($LHS_parens)
Branch: 1 branch
BranchTrueFalseTotal
if ($LHS_parens) 0 0 0
703 {
704 0 $LHS = $self->_test($quote.$LHS_parens.$quote);
705 0 ▶ if ($pound) {$LHS = !$LHS;}
Branch: 1 branch
BranchTrueFalseTotal
if ($pound) 0 0 0
706 0 return $LHS;
707 }
708 0 $test = $LHS; # NOTE: is this redundant?
709 }
710 elsif ($RHS) # unbalanced quotes
711 0 { $test = $RHS; } # NOTE: is this redundant?
712 }
713 }
714 else {
715 0 return $self->SSI_ERROR("unknown error in expression."); # SHOULD NOT REACH THIS
716 }
717 }
718
719
720 #--------------------------
721 # BAREWORD (no comparison sign)
722 0 ▶ if ($test =~ /^(?:$RE_all_quote_NC|(?:[^=<>\/]|[\\]\/)*)$/) # BAREWORD
Branch: 1 branch
BranchTrueFalseTotal
if ($test =~ m(^(?:$CGI::apacheSSI::RE_all_quote_NC|(?:[^=<>/]|[\\]/)*)$)) 0 0 0
723 {
724 0 ▶ if ($test =~ /^(['])(.*?)(?:\1)$/) {$test=$2;} # need to trim surrounding single quotes
Branch: 1 branch
BranchTrueFalseTotal
if ($test =~ /^(['])(.*?)(?:\1)$/) 0 0 0
725 0 ▶ if ($test =~ /^$/) {return ($pound);} # no need to parse
Branch: 1 branch
BranchTrueFalseTotal
if ($test =~ /^$/) 0 0 0
726 0 ▶ if ($test =~ /^["]/) {return (! $pound);} # no need to parse
Branch: 1 branch
BranchTrueFalseTotal
if ($test =~ /^["]/) 0 0 0
727
728 0 my $interp_test = $self->_interp_vars($test);
729 0 my $RET = ($interp_test =~ /[^']+/);
730 0 ▶ if ($interp_test ne $test)
Branch: 1 branch
BranchTrueFalseTotal
if ($interp_test ne $test) 0 0 0
731 { # var interpolation occurred, NOTE: apache deems only '' or empty to be false in this case.
732 0 $test = ($interp_test !~ /^$/) ;
733 0 ▶ return (($pound) xor ($test));
Condition0%0/4
$pound ^^ $test
l&&rl&&!r!l&&r!l&&!r
0000
MC/DC0%0/2
$pound ^^ $test
$pound $test
Truth table0%0/4
A ^^ B
A= $poundB= $test
ABresult
110
101
011
000
734 }
735 0 ▶ return (($pound) xor ($RET)); # non empty string is true,
Condition0%0/4
$pound ^^ $RET
l&&rl&&!r!l&&r!l&&!r
0000
MC/DC0%0/2
$pound ^^ $RET
$pound $RET
Truth table0%0/4
A ^^ B
A= $poundB= $RET
ABresult
110
101
011
000
736 }
737
738
739 #--------------------------
740 # STRING COMPARISON >,<,==,!=,=~
741 0 ▶ if ($test =~ m{ \s*((?:$RE_all_quote_NC|[^<>=])*?)\s*([<>=!]=?)\s*([^<>=]*)\s* }x)
Branch: 1 branch
BranchTrueFalseTotal
if ($test =~ / \s*((?:$CGI::apacheSSI::RE_all_quote_NC|[^<>=])*?)\s*([<>=!]=?)\s*([^<>=]*)\s* /x) { } 0 0 0
742 {
743 0 ▶ if ($pounds)
Branch: 1 branch
BranchTrueFalseTotal
if ($pounds) 0 0 0
744 0 { return $self->SSI_ERROR("invalid expression $quote$test$quote in file"); } # NOTE: FIXME
745
746 0 my ($s1,$cmp,$s2)=($1, $2, $3);
747 0 ▶ if ($s1=~/^\s*$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($s1 =~ /^\s*$/) 0 0 0
748 0 { return $self->SSI_ERROR("problem in REGEX. blank comparison \$s1"); } # NOTE: FIXME
749 0 ▶ if ($s2=~/^\s*$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($s2 =~ /^\s*$/) 0 0 0
750 0 { return $self->SSI_ERROR("problem in REGEX. blank comparison \$s2"); } # NOTE: FIXME
751
752 0 ▶ if ($s2 =~ m{^ \s* (?: (?:/\s*[^/]*) | // ) \s* $}x) # NOTE: what about escaped or stringed
Branch: 1 branch
BranchTrueFalseTotal
if ($s2 =~ m[^ \s* (?: (?:/\s*[^/]*) | // ) \s* $]x) 0 0 0
753 {
754 0 ▶ if ($cmp =~ m/^==?$/) {return 1;}
Branch: 2 branches
BranchTrueFalseTotal
if ($cmp =~ /^==?$/) { } 0 0 0
elsif ($cmp =~ /^!=$/) { } 0 0 0
755 0 elsif ($cmp =~ m/^!=$/) {return;}
756 0 else { return $self->SSI_ERROR("Invalid expression $quote$test$quote in string comparison."); }
757 }
758
759 0 $s1=$self->_interp_vars($s1);
760 0 ▶ if ($s1 =~ /^(['"`])(.*?)(?:\1)$/) {$s1=$2;} # trim off surrounding (matching) quotes
Branch: 1 branch
BranchTrueFalseTotal
if ($s1 =~ /^(['"`])(.*?)(?:\1)$/) 0 0 0
761
762 # REGEX
763 0 ▶ if ($s2 =~ m{^\s* / ((?:(?:(?:\\\\)*\\/) | [^/] )*) / (.*?)\s*$}x) # wrapped by /xx/
Branch: 1 branch
BranchTrueFalseTotal
if ($s2 =~ m[^\s* / ((?:(?:(?:\\\\)*\\/) | [^/] )*) / (.*?)\s*$]x) { } 0 0 0
764 {
765 0 ▶ if ($2)
Branch: 1 branch
BranchTrueFalseTotal
if ($2) 0 0 0
766 0 { return $self->SSI_ERROR("problem in REGEX. s2=[$s2] extra stuff=[$2]"); } # NOTE: FIXME
767 0 $s2=qr/$1/; # regex s2
768 0 $s2 = $self->_interp_vars($s2);
769 0 ▶ if ($cmp =~ m/^==?$/)
Branch: 2 branches
BranchTrueFalseTotal
if ($cmp =~ /^==?$/) { } 0 0 0
elsif ($cmp eq '!=') { } 0 0 0
770 0 { return ($s1 =~ m/$s2/);}
771 elsif ($cmp eq "!=")
772 0 { return ($s1 !~ $s2); } # NOTE: FIXME!!!
773 }
774 else {
775 0 ▶ if ($s2=~m|^[^\s/]+\s+/|) # unquoted, unescaped slash
Branch: 1 branch
BranchTrueFalseTotal
if ($s2 =~ m[^[^\s/]+\s+/]) 0 0 0
776 0 { return $self->SSI_ERROR("problem in REGEX unquoted slash. s2=[$s2]"); } # NOTE: FIXME
777
778 0 $s2 = $self->_interp_vars($s2);
779 0 ▶ if ($s2 =~ /^(['"])(.*?)(\1)$/) {$s2 = $2;} # trim off surrounding (matching) quotes
Branch: 1 branch
BranchTrueFalseTotal
if ($s2 =~ /^(['"])(.*?)(\1)$/) 0 0 0
780 }
781
782 0 my $ret;
783 0 $ret = $s1 cmp $s2;
784
785 0 ▶ if ($cmp =~ m/^==?$/) {$ret = ($ret eq 0);}
Branch: 6 branches
BranchTrueFalseTotal
if ($cmp =~ /^==?$/) { } 0 0 0
elsif ($cmp =~ /^!=$/) { } 0 0 0
elsif ($cmp =~ /^<$/) { } 0 0 0
elsif ($cmp =~ /^<=$/) { } 0 0 0
elsif ($cmp =~ /^>$/) { } 0 0 0
elsif ($cmp =~ /^>=$/) { } 0 0 0
786 0 elsif ($cmp =~ m/^!=$/) {$ret = ($ret ne 0);}
787
788 0 elsif ($cmp =~ m/^<$/) {$ret = ($ret lt 0);}
789 0 elsif ($cmp =~ m/^<=$/) {$ret = ($ret le 0);}
790
791 0 elsif ($cmp =~ m/^>$/) {$ret = ($ret gt 0);}
792 0 elsif ($cmp =~ m/^>=$/) {$ret = ($ret ge 0);}
793
794 0 else { return $self->SSI_ERROR("unknown comparison"); } # UNKNOWN COMPARISON -- should never reach this
795
796 0 return $ret;
797 }
798 else {
799 0 ▶ if ($test =~ m{[^/]+\s+/}) # NOTE: UNFINISHED!! FIXME non empty unrecognized string that didnt fail
Branch: 1 branch
BranchTrueFalseTotal
if ($test =~ m[[^/]+\s+/]) 0 0 0
800 0 { return $self->SSI_ERROR("error in expression, regex found in string"); }
801 0 return 1;
802 }
803
804 0 return; # return false.. it seems none of the ops applied..
805 }
806
807 sub _entering_if {
808 0 ▶ my $self = shift;
Subroutine _entering_if: not called CC=1 SCAR=6.9
809 0 $self->{'_in_if'}++;
810 0 $self->{'_suspend'}->[$self->{'_in_if'}] = $self->{'_suspend'}->[$self->{'_in_if'} - 1];
811 0 $self->{'_seen_true'}->[$self->{'_in_if'}] = 0;
812 }
813
814 sub _seen_true {
815 0 ▶ my $self = shift;
Subroutine _seen_true: not called CC=1 SCAR=6.9
816 0 return $self->{'_seen_true'}->[$self->{'_in_if'}];
817 }
818
819 sub _suspended {
820 114 ▶ my $self = shift;
Subroutine _suspended: called CC=1 SCAR=0.0
821 114 return $self->{'_suspend'}->[$self->{'_in_if'}];
822 }
823
824 sub _leaving_if {
825 0 ▶ my $self = shift;
Subroutine _leaving_if: not called CC=2 SCAR=17.9
826 0 ▶ $self->{'_in_if'}-- if $self->{'_in_if'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_in_if"} 0 0 0
827 }
828
829 sub _true {
830 0 ▶ my $self = shift;
Subroutine _true: not called CC=1 SCAR=6.9
831 0 return $self->{'_seen_true'}->[$self->{'_in_if'}]++;
832 }
833
834 sub _suspend {
835 0 ▶ my $self = shift;
Subroutine _suspend: not called CC=1 SCAR=6.9
836 0 $self->{'_suspend'}->[$self->{'_in_if'}]++;
837 }
838
839 sub _resume {
840 0 ▶ my $self = shift;
Subroutine _resume: not called CC=2 SCAR=17.9
841 $self->{'_suspend'}->[$self->{'_in_if'}]--
842 0 ▶ if $self->{'_suspend'}->[$self->{'_in_if'}];
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_suspend"}[$self->{"_in_if"}] 0 0 0
843 }
844
845 sub _in_if {
846 0 ▶ my $self = shift;
Subroutine _in_if: not called CC=1 SCAR=6.9
847 0 return $self->{'_in_if'};
848 }
849
850 sub if {
851 0 ▶ my($self,$expr,$test) = @_;
Subroutine if: not called CC=4 SCAR=30.0
Pod documented
852 0 ▶ $expr = $test if @_ == 3;
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 3 0 0 0
853 0 $self->_entering_if();
854
855 0 my $res=$self->_test($expr);
856
857 0 ▶ if($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
858 0 $self->_true();
859 0 return;
860 } # any errors cause the expr to evaluate to true..??
861
862 0 ▶ if($res) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res) { } 0 0 0
863 0 $self->_true();
864 } else {
865 0 $self->_suspend();
866 }
867 0 return '';
868 }
869
870 sub elif {
871 0 ▶ my($self,$expr,$test) = @_;
Subroutine elif: not called CC=10 SCAR=47.0
Pod documented
872
873 0 ▶ if (! $self->_in_if() ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_in_if) 0 0 0
874 0 $self->SSI_WARN("Incorrect use of elif ssi directive: no preceeding 'if'."); # NOTE: just a "warn"
875 0 ▶ $self->_suspend() unless $self->_suspended();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_suspended 0 0 0
876 0 return;
877 }
878
879 0 ▶ if ($self->_seen_true()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_seen_true) 0 0 0
880 0 ▶ $self->_suspend() unless $self->_suspended();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_suspended 0 0 0
881 0 return;
882 }
883
884 0 ▶ $expr = $test if @_ == 3;
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 3 0 0 0
885
886
887 0 my $res= $self->_test($expr);
888
889 0 ▶ if($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
890 0 ▶ $self->_suspend() unless $self->_suspended();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_suspended 0 0 0
891 0 return;
892 }
893
894 0 ▶ if($res) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res) { } 0 0 0
895 0 $self->_true();
896 0 $self->_resume();
897 } else {
898 0 ▶ $self->_suspend() unless $self->_suspended();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_suspended 0 0 0
899 }
900 0 return '';
901 }
902
903 sub else {
904 0 ▶ my $self = shift;
Subroutine else: not called CC=5 SCAR=34.0
Pod documented
905
906 0 ▶ if (! $self->_in_if() ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_in_if) 0 0 0
907 0 $self->SSI_WARN("Incorrect use of else ssi directive: no preceeding 'if'."); # NOTE: just a "warn"
908 0 ▶ $self->_suspend() unless $self->_suspended();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_suspended 0 0 0
909 0 return;
910 }
911 0 ▶ if ($self->_seen_true()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_seen_true) { } 0 0 0
912 0 ▶ $self->_suspend() unless $self->_suspended(); }
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_suspended 0 0 0
913 else {
914 0 $self->_resume(); }
915 0 return '';
916 }
917
918 sub endif {
919 0 ▶ my $self = shift;
Subroutine endif: not called CC=3 SCAR=24.8
Pod documented
920 0 ▶ if (! $self->_in_if() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->_in_if) { } 0 0 0
921 0 $self->SSI_WARN("Incorrect use of endif ssi directive: no preceeding 'if'.");
922 }
923 else
924 0 { $self->_leaving_if(); }
925 0 ▶ $self->_resume() if $self->_suspended(); # might be suspended even if not in "if"
Branch: 1 branch
BranchTrueFalseTotal
if $self->_suspended 0 0 0
926 0 return '';
927 }
928
929 #
930 # if we're called like this, it means that we're to handle a CGI request ourselves.
931 # that means that we're to open the file and process the content, sending it to STDOUT
932 # along with a standard HTTP content header
933 #
934 2 ▶unless(caller) {
Branch: 1 branch
BranchTrueFalseTotal
unless (caller) 0 2 2
935 0 goto &handler;
936 }
937
938 sub handler {
939 0 ▶ eval "use CGI qw(:standard);";
Subroutine handler: not called CC=4 SCAR=30.0
Pod undocumented
940 0 print header();
941
942 0 ▶ unless(UNIVERSAL::isa(tied(*STDOUT),'CGI::apacheSSI')) {
Branch: 1 branch
BranchTrueFalseTotal
unless (UNIVERSAL::isa(tied *STDOUT, "CGI::apacheSSI")) 0 0 0
943 0 tie *STDOUT, 'CGI::apacheSSI', filehandle => 'main::STDOUT';
944 }
945
946 0 my $filename = "$ENV{DOCUMENT_ROOT}$ENV{REQUEST_URI}";
947 0 ▶ if(-f $filename) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $filename) { } 0 0 0
948 0 ▶ open my $fh, '<', $filename or die "Failed to open file ($filename): $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $filename or die "Failed to open file ($filename): $!" 0 0 0
949 0 print <$fh>;
950 } else {
951 0 print "Failed to find file ($filename).";
952 }
953
954 0 exit;
955 }
956
957 #
958 # packages for tie()
959 #
960
961 package CGI::apacheSSI::Gmt;
962
963 18 ▶sub TIESCALAR { bless [@_], shift() }
Subroutine TIESCALAR: called CC=1 SCAR=0.0
964 sub FETCH {
965 18 ▶ my $self = shift;
Subroutine FETCH: called CC=2 SCAR=8.4
966 18 ▶ if($self->[-1]->{'_config'}->{'timefmt'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[-1]{'_config'}{'timefmt'}) { } 0 18 18
967 0 my @gt = gmtime;
968 0 return Date::Format::strftime($self->[-1]->{'_config'}->{'timefmt'},@gt);
969 } else {
970 18 return scalar gmtime;
971 }
972 }
973
974 package CGI::apacheSSI::Local;
975
976 18 ▶sub TIESCALAR { bless [@_], shift() }
Subroutine TIESCALAR: called CC=1 SCAR=0.0
977 sub FETCH {
978 19 ▶ my $self = shift;
Subroutine FETCH: called CC=2 SCAR=6.9
979 19 ▶ if($self->[-1]->{'_config'}->{'timefmt'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[-1]{'_config'}{'timefmt'}) { } 1 18 19
980 1 my @lt = localtime;
981 1 return Date::Format::strftime($self->[-1]->{'_config'}->{'timefmt'},@lt);
982 } else {
983 18 return scalar localtime;
984 }
985 }
986
987 package CGI::apacheSSI::LMOD;
988
989 18 ▶sub TIESCALAR { bless [@_], shift() }
Subroutine TIESCALAR: called CC=1 SCAR=0.0
990 sub FETCH {
991 20 ▶ my $self = shift;
Subroutine FETCH: called CC=3 SCAR=13.1
992 20 ▶ return $self->[-1]->flastmod('file', $ENV{'SCRIPT_FILENAME'} || $ENV{'PATH_TRANSLATED'} || '');
Condition40%2/5
$ENV{'SCRIPT_FILENAME'} || $ENV{'PATH_TRANSLATED'} || ''
l!l
020
$ENV{"SCRIPT_FILENAME"} or $ENV{"PATH_TRANSLATED"}
l!l&&r!l&&!r
0020
MC/DC0%0/2
$ENV{'SCRIPT_FILENAME'} || $ENV{'PATH_TRANSLATED'} || ''
$ENV{"SCRIPT_FILENAME"} $ENV{"PATH_TRANSLATED"}
Truth table33%1/3
A or B
A= $ENV{"SCRIPT_FILENAME"}B= $ENV{"PATH_TRANSLATED"}
ABresult
1X1
011
000
993 }
994
995 2 1;
996 __END__
↑ Summary