WWW/CGI.pm

filter: Statementstmt 18.7% 55 / 294 Branchbran 0.0% 0 / 134 Conditioncond 0.0% 0 / 84 MC/DCmcdc 0.0% 0 / 48 Subroutinesub 22.9% 17 / 74 Podpod 100% 52 / 52 totaltotal 18.0% 124 / 686 CC 106 SCAR 40.3
CC
106
Cov
11%
vars
240.0
fromRequest
210.0
uri
90.0
CRAP 56.2
« WWW/Server.pm ↑ Summary WWW/Handler.pm »
1 ##-*- Mode: CPerl; coding: utf-8; -*-
2 ##
3 ## File: DiaColloDB/WWW/CGI.pm
4 ## Author: Bryan Jurish <moocow@cpan.org>
5 ## Description: collocation db, www wrappers: (f)cgi handler
6 ## + adapted from DbCgi.pm ( svn+ssh://odo.dwds.de/home/svn/dev/dbcgi/trunk/DbCgi.pm )
7  
8 package DiaColloDB::WWW::CGI;
9 2 ▶use DiaColloDB;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use DiaColloDB::Logger;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use CGI qw(:standard :cgi-lib);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use URI::Escape qw(uri_escape_utf8);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use HTTP::Status;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use Encode qw(); #qw(encode decode encode_utf8 decode_utf8);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use File::Basename qw(basename dirname);
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use File::ShareDir qw(); ##-- for shared template data
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use Cwd qw(getcwd abs_path);
Subroutine BEGIN: called CC=1 SCAR=0.0
19 #use LWP::UserAgent;
20 1 ▶use Template;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use JSON qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶use Time::HiRes qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
23 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
28 #binmode(STDIN, ':utf8');
29 #binmode(STDOUT,':utf8');
30 1 binmode(STDERR,':utf8');
31 }
32  
33 1 *isa = \&UNIVERSAL::isa;
34 1 *can = \&UNIVERSAL::can;
35  
36 ##======================================================================
37 ## globals
38  
39 1 our $VERSION = "0.02.005";
40 1 our @ISA = qw(DiaColloDB::Logger);
41  
42 ##======================================================================
43 ## constructors etc.
44  
45 ## $dbcgi = $that->new(%args)
46 ## + %args, object structure:
47 ## (
48 ## ##-- basic stuff
49 ## prog => basename($0),
50 ## ##
51 ## ##-- underlying CGI module
52 ## cgipkg => 'CGI',
53 ## ##
54 ## ##-- CGI params
55 ## defaults => {},
56 ## vars => undef,
57 ## charset => 'utf-8',
58 ## nodecode => {}, ##-- vars not to decode
59 ## ##
60 ## ##-- CGI environment stuff : see getenv() method
61 ## remote_addr => undef,
62 ## remote_user => undef,
63 ## request_method => undef,
64 ## request_uri => undef,
65 ## request_query => undef,
66 ## http_referer => undef,
67 ## http_host => undef,
68 ## server_addr => undef,
69 ## server_port => undef,
70 ## ##
71 ## ##-- template toolkit stuff
72 ## ttk_package => (ref($that)||$that),
73 ## ttk_vars => {}, ##-- template vars
74 ## ttk_config => {ENCODING=>'utf8'}, ##-- options for Template->new()
75 ## ttk_process => {binmode=>':utf8'}, ##-- options for Template->process()
76 ## ttk_dir => abs_path(dirname($0)),
77 ## ttk_key => undef, ##-- current template basename
78 ## ttk_rawkeys => { ##-- pseudo-set of raw keys
79 ## profile=>1,
80 ## },
81 ## ##
82 ## ##-- File::ShareDir stuff (fallbacks for ttk_dir)
83 ## ttk_sharedir => File::ShareDir::dist_dir("DiaColloDB-WWW")."/htdocs",
84 ## )
85 0 ▶sub new {
Subroutine new: not called CC=5 SCAR=34.0
Pod documented
86 0 my $that = shift;
87 0 ▶ my $dbcgi = bless({
Condition0%0/6
ref $that || $that
l!l&&r!l&&!r
000
ref $that || $that
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $that || $that
ref $that $that
MC/DC0%0/2
ref $that || $that
ref $that $that
Truth table0%0/3
A || B
A= ref $thatB= $that
ABresult
1X1
011
000
Truth table0%0/3
A || B
A= ref $thatB= $that
ABresult
1X1
011
000
88 ##-- basic stuff
89 prog => basename($0),
90 ##
91 ##-- underlying CGI module
92 cgipkg => 'CGI',
93 ##
94 ##-- CGI params
95 defaults => {},
96 vars => undef,
97 charset => 'utf-8',
98 nodecode => {}, ##-- vars not to decode
99 ##
100 ##-- CGI environment stuff : see getenv() method
101 remote_addr => undef,
102 remote_user => undef,
103 request_method => undef,
104 request_uri => undef,
105 request_query => undef,
106 http_referer => undef,
107 http_host => undef,
108 server_addr => undef,
109 server_port => undef,
110 ##
111 ##-- template toolkit stuff
112 ttk_package => (ref($that)||$that),
113 ttk_vars => {}, ##-- template vars
114 ttk_config => {ENCODING=>'utf8'}, ##-- options for Template->new()
115 ttk_process => {binmode=>':utf8'}, ##-- options for Template->process()
116 ttk_dir => abs_path(dirname($0)),
117 ttk_key => undef, ##-- current template basename
118 ttk_rawkeys => { ##-- pseudo-set of raw keys
119 profile=>1,
120 },
121 ##
122 ##-- File::ShareDir stuff (fallbacks for ttk_dir)
123 ttk_sharedir => File::ShareDir::dist_dir("DiaColloDB-WWW")."/htdocs",
124 ##
125 ##-- user args
126 @_,
127 }, ref($that)||$that);
128  
129 ##-- CGI package
130 0 ▶ if ($dbcgi->{cgipkg}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dbcgi->{"cgipkg"}) 0 0 0
131 0 eval "use $dbcgi->{cgipkg} qw(:standard :cgi-lib);";
132 0 ▶ $dbcgi->logconfess("new(): could not use {cgipkg} $dbcgi->{cgipkg}: $@") if ($@);
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
133 }
134  
135 ##-- environment defaults
136 0 $dbcgi->_getenv();
137  
138 0 return $dbcgi;
139 }
140  
141 ## @keys = $dbcgi->_param()
142 ## $val = $dbcgi->_param($name)
143 0 ▶sub _param {
Subroutine _param: not called CC=1 SCAR=6.9
144 0 my $dbcgi = shift;
145 0 return $dbcgi->cgi('param',@_);
146 }
147  
148 ## $dbcgi = $dbcgi->_reset()
149 ## + resets CGI environment
150 0 ▶sub _reset {
Subroutine _reset: not called CC=1 SCAR=6.9
151 0 my $dbcgi = shift;
152 0 delete @$dbcgi{(qw(vars),
153 qw(remote_addr remote_user),
154 qw(request_method request_uri request_query),
155 qw(http_referer http_host server_addr server_port),
156 )};
157 0 return $dbcgi;
158 }
159  
160 ## $dbcgi = $dbcgi->_getenv()
161 0 ▶sub _getenv {
Subroutine _getenv: not called CC=5 SCAR=34.0
162 0 my $dbcgi = shift;
163 0 ▶ $dbcgi->{remote_addr} = ($ENV{REMOTE_ADDR}||'0.0.0.0');
Condition0%0/2
$ENV{'REMOTE_ADDR'} || '0.0.0.0'
l!l
00
MC/DC0%0/1
$ENV{'REMOTE_ADDR'} || '0.0.0.0'
$ENV{'REMOTE_ADDR'}
Truth table0%0/2
A
A= $ENV{'REMOTE_ADDR'}
Aresult
11
00
164 0 ▶ $dbcgi->{remote_user} = ($ENV{REMOTE_USER} || getpwuid($>));
Condition0%0/3
$ENV{'REMOTE_USER'} || getpwuid $>
l!l&&r!l&&!r
000
MC/DC0%0/2
$ENV{'REMOTE_USER'} || getpwuid $>
$ENV{'REMOTE_USER'} getpwuid $>
Truth table0%0/3
A || B
A= $ENV{'REMOTE_USER'}B= getpwuid $>
ABresult
1X1
011
000
165 0 ▶ $dbcgi->{request_method} = ($ENV{REQUEST_METHOD}||'GET');
Condition0%0/2
$ENV{'REQUEST_METHOD'} || 'GET'
l!l
00
MC/DC0%0/1
$ENV{'REQUEST_METHOD'} || 'GET'
$ENV{'REQUEST_METHOD'}
Truth table0%0/2
A
A= $ENV{'REQUEST_METHOD'}
Aresult
11
00
166 0 ▶ $dbcgi->{request_uri} = ($ENV{REQUEST_URI} || $0);
Condition0%0/3
$ENV{'REQUEST_URI'} || $0
l!l&&r!l&&!r
000
MC/DC0%0/2
$ENV{'REQUEST_URI'} || $0
$ENV{'REQUEST_URI'} $0
Truth table0%0/3
A || B
A= $ENV{'REQUEST_URI'}B= $0
ABresult
1X1
011
000
167 0 $dbcgi->{request_query} = $ENV{QUERY_STRING};
168 0 $dbcgi->{http_referer} = $ENV{HTTP_REFERER};
169 0 $dbcgi->{http_host} = $ENV{HTTP_HOST};
170 0 $dbcgi->{server_addr} = $ENV{SERVER_ADDR};
171 0 $dbcgi->{server_port} = $ENV{SERVER_PORT};
172 0 return $dbcgi;
173 }
174  
175 ## $dbcgi = $dbcgi->fromRequest($httpRequest,$csock)
176 ## + sets up $dbcgi from an HTTP::Request object
177 0 ▶sub fromRequest {
Subroutine fromRequest: not called CC=14 SCAR=53.5
Pod documented
178 0 my ($dbcgi,$hreq,$csock) = @_;
179  
180 ##-- setup pseudo-environment
181 0 my $uri = $hreq->uri;
182 0 my @path = grep {$_ ne ''} $uri->path_segments;
183 0 ▶ $dbcgi->{prog} = $path[$#path] || 'index';
Condition0%0/2
$path[$#path] || 'index'
l!l
00
MC/DC0%0/1
$path[$#path] || 'index'
$path[$#path]
Truth table0%0/2
A
A= $path[$#path]
Aresult
11
00
184 0 ▶ $dbcgi->{remote_addr} = $ENV{REMOTE_ADDR} = $csock ? $csock->peerhost : '0.0.0.0';
Branch: 1 branch
BranchTrueFalseTotal
$csock ? : 0 0 0
185 0 ▶ $dbcgi->{remote_port} = $ENV{REMOTE_PORT} = $csock ? $csock->peerport : '0';
Branch: 1 branch
BranchTrueFalseTotal
$csock ? : 0 0 0
186 0 $dbcgi->{remote_user} = $ENV{REMOTE_USER} = '';
187 0 $dbcgi->{request_method} = $ENV{REQUEST_METHOD} = $hreq->method;
188 0 $dbcgi->{request_uri} = $ENV{REQUEST_URI} = $uri->as_string;
189 0 $dbcgi->{request_query} = $ENV{REQUEST_QUERY} = $uri->query;
190 0 $dbcgi->{http_referer} = $ENV{HTTP_REFERER} = $hreq->referer;
191 0 ▶ $dbcgi->{http_host} = $ENV{HTTP_HOST} = $uri->host || $csock->sockhost;
Condition0%0/3
$uri->host || $csock->sockhost
l!l&&r!l&&!r
000
MC/DC0%0/2
$uri->host || $csock->sockhost
$uri->host $csock->sockhost
Truth table0%0/3
A || B
A= $uri->hostB= $csock->sockhost
ABresult
1X1
011
000
192 0 ▶ $dbcgi->{server_addr} = $ENV{SERVER_ADDR} = $csock ? $csock->sockaddr : '0.0.0.0';
Branch: 1 branch
BranchTrueFalseTotal
$csock ? : 0 0 0
193 0 ▶ $dbcgi->{server_port} = $ENV{SERVER_PORT} = $csock ? $csock->sockport : '0';
Branch: 1 branch
BranchTrueFalseTotal
$csock ? : 0 0 0
194  
195 ##-- setup variables
196 0 my %vars = $uri->query_form;
197 0 ▶ my $addVars = sub {
Subroutine __ANON__: not called CC=5 SCAR=34.0
198 0 my $add = shift;
199 0 foreach (grep {defined $add->{$_}} keys %$add) {
200 0 ▶ if (!exists($vars{$_})) {
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $vars{$_}) { } 0 0 0
201 0 $vars{$_} = $add->{$_};
202 } else {
203 0 ▶ $vars{$_} = [ $vars{$_} ] if (!ref($vars{$_}));
Branch: 1 branch
BranchTrueFalseTotal
unless ref $vars{$_} 0 0 0
204 0 ▶ push(@{$vars{$_}}, ref($add->{$_}) ? @{$add->{$_}} : $add->{$_});
Branch: 1 branch
BranchTrueFalseTotal
ref $add->{$_} ? : 0 0 0
205 }
206 }
207 0 };
208 0 ▶ if ($hreq->method eq 'POST') {
Branch: 1 branch
BranchTrueFalseTotal
if ($hreq->method eq "POST") 0 0 0
209 0 ▶ if ($hreq->content_type eq 'application/x-www-form-urlencoded') {
Branch: 3 branches
BranchTrueFalseTotal
if ($hreq->content_type eq 'application/x-www-form-urlencoded') { } 0 0 0
elsif ($hreq->content_type eq 'multipart/form-data') { } 0 0 0
elsif ($hreq->content_length > 0) { } 0 0 0
210 ##-- POST: x-www-form-urlencoded
211 0 $addVars->( {URI->new('?'.$hreq->content)->query_form} );
212 }
213 elsif ($hreq->content_type eq 'multipart/form-data') {
214 ##-- POST: multipart/form-data: parse by hand
215 0 foreach my $part ($hreq->parts) {
216 0 my $pdis = $part->header('Content-Disposition');
217 0 ▶ if ($pdis =~ /^form-data\b/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pdis =~ /^form-data\b/) 0 0 0
218 ##-- POST: multipart/form-data: part: form-data; name="PARAMNAME"
219 0 ▶ if ($pdis =~ /\bname=[\"\']?([\w\-\.\,\+]*)[\'\"]?/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pdis =~ /\bname=[\"\']?([\w\-\.\,\+]*)[\'\"]?/) 0 0 0
220 0 $addVars->({ $1 => $part->content });
221 0 next;
222 }
223 }
224 ##-- POST: multipart/form-data: part: anything other than 'form-data; name="PARAMNAME"'
225 0 $addVars->({ POSTDATA => $part->content });
226 }
227 }
228 elsif ($hreq->content_length > 0) {
229 ##-- POST: anything else: use POSTDATA
230 0 $addVars->({ POSTDATA => $hreq->content });
231 }
232 }
233 0 $dbcgi->vars(\%vars);
234  
235 0 return $dbcgi;
236 }
237  
238  
239 ## \%vars = $dbcgi->vars()
240 ## \%vars = $dbcgi->vars(\%vars)
241 ## + get/set CGI variables, instantiating $dbcgi->{defaults} if present
242 0 ▶sub vars {
Subroutine vars: not called CC=15 SCAR=54.8
Pod documented
243 0 my ($dbcgi,$vars) = @_;
244 0 ▶ return $dbcgi->{vars} if (defined($dbcgi->{vars}) && !defined($vars));
Branch: 1 branch
BranchTrueFalseTotal
if defined $dbcgi->{"vars"} and not defined $vars 0 0 0
Condition0%0/3
defined $dbcgi->{"vars"} and not defined $vars
!ll&&!rl&&r
000
MC/DC0%0/2
defined $dbcgi->{"vars"} and not defined $vars
defined $dbcgi->{"vars"} not defined $vars
Truth table0%0/3
A and not(B)
A= defined $dbcgi->{"vars"}B= not defined $vars
ABresult
0X0
100
111
245 0 ▶ $vars ||= $dbcgi->cgi('param') ? { %{$dbcgi->cgi('Vars')} } : {};
Branch: 1 branch
BranchTrueFalseTotal
$dbcgi->cgi('param') ? : 0 0 0
Condition0%0/3
$vars ||= $dbcgi->cgi("param") ? {%{$dbcgi->cgi("Vars");}} : {}
l!l&&r!l&&!r
000
MC/DC0%0/2
$vars ||= $dbcgi->cgi("param") ? {%{$dbcgi->cgi("Vars");}} : {}
$vars $dbcgi->cgi("param") ? {%{$dbcgi->cgi("Vars");}} : {}
Truth table0%0/3
A ||= B
A= $varsB= $dbcgi->cgi("param") ? {%{$dbcgi->cgi("Vars");}} : {}
ABresult
1X1
011
000
246  
247 0 ▶ if (($dbcgi->{cgipkg}//'CGI') ne 'CGI' || defined($vars->{POSTDATA})) {
Branch: 1 branch
BranchTrueFalseTotal
if (($dbcgi->{"cgipkg"} // "CGI") ne "CGI" or defined $vars->{"POSTDATA"}) 0 0 0
Condition0%0/5
($dbcgi->{"cgipkg"} // "CGI") ne "CGI" or defined $vars->{"POSTDATA"}
l!l&&r!l&&!r
000
$dbcgi->{"cgipkg"} // "CGI"
l!l
00
MC/DC0%0/2
($dbcgi->{"cgipkg"} // "CGI") ne "CGI" or defined $vars->{"POSTDATA"}
$dbcgi->{"cgipkg"} defined $vars->{"POSTDATA"}
Truth table0%0/3
A or B
A= $dbcgi->{"cgipkg"}B= defined $vars->{"POSTDATA"}
ABresult
1X1
011
000
248 ##-- parse params from query string; required e.g. for CGI::Fast or non-form POST requests (which set POSTDATA)
249 0 my $uri = URI->new($dbcgi->{request_uri});
250 0 my %urif = $uri->query_form();
251 0 @$vars{keys %urif} = values %urif;
252 }
253  
254 0 ▶ foreach (grep {!exists($vars->{$_}) && defined($dbcgi->{defaults}{$_})} keys %{$dbcgi->{defaults}||{}}) {
Condition0%0/5
!exists $vars->{$_} && defined $dbcgi->{'defaults'}{$_}
!ll&&!rl&&r
000
$dbcgi->{'defaults'} || {}
l!l
00
MC/DC0%0/2
!exists $vars->{$_} && defined $dbcgi->{'defaults'}{$_}
!exists $vars->{$_} defined $dbcgi->{'defaults'}{$_}
MC/DC0%0/1
$dbcgi->{'defaults'} || {}
$dbcgi->{'defaults'}
Truth table0%0/3
not(A) && B
A= !exists $vars->{$_}B= defined $dbcgi->{'defaults'}{$_}
ABresult
0X0
100
111
Truth table0%0/2
A
A= $dbcgi->{'defaults'}
Aresult
11
00
255 ##-- defaults
256 0 $vars->{$_} = $dbcgi->{defaults}{$_}
257 }
258 0 my ($tmp);
259 0 foreach (keys %$vars) {
260 ##-- decode (annoying temporary variable hack hopefully ensures that utf8 flag is set!)
261 0 $tmp = $vars->{$_};
262 0 $tmp =~ s/\x{0}/ /g;
263 0 ▶ if ($dbcgi->{charset} && !utf8::is_utf8($tmp) && !exists($dbcgi->{nodecode}{$_})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dbcgi->{"charset"} and not utf8::is_utf8($tmp) and not exists $dbcgi->{"nodecode"}{$_}) 0 0 0
Condition0%0/6
$dbcgi->{"charset"} and not utf8::is_utf8($tmp) and not exists $dbcgi->{"nodecode"}{$_}
!ll&&!rl&&r
000
$dbcgi->{"charset"} and not utf8::is_utf8($tmp)
!ll&&!rl&&r
000
MC/DC0%0/3
$dbcgi->{"charset"} and not utf8::is_utf8($tmp) and not exists $dbcgi->{"nodecode"}{$_}
$dbcgi->{"charset"} not utf8::is_utf8($tmp) not exists $dbcgi->{"nodecode"}{$_}
Truth table0%0/4
A and not(B) and not(C)
A= $dbcgi->{"charset"}B= not utf8::is_utf8($tmp)C= not exists $dbcgi->{"nodecode"}{$_}
ABCresult
0XX0
10X0
1100
1111
264 0 $tmp = Encode::decode($dbcgi->{charset},$tmp);
265 #$dbcgi->trace("decode var '$_':\n+ OLD=$vars->{$_}\n+ NEW=$tmp\n");
266 0 $vars->{$_} = $tmp;
267 }
268 }
269 0 return $dbcgi->{vars} = $vars;
270 }
271  
272 ##======================================================================
273 ## config loading (optional)
274  
275 ## $dbcgi = $dbcgi->load_config($filename)
276 ## + clobers %$dbcgi keys from JSON filename
277 0 ▶sub load_config {
Subroutine load_config: not called CC=4 SCAR=30.0
Pod documented
278 0 my ($dbcgi,$file) = @_;
279 0 ▶ open(RC,"<:raw",$file)
Branch: 1 branch
BranchTrueFalseTotal
open RC, "<:raw", $file or $dbcgi->logconfess("load_config(): failed for '${file}': $!") 0 0 0
280 or $dbcgi->logconfess("load_config(): failed for '$file': $!");
281 0 local $/ = undef;
282 0 my $buf = <RC>;
283 0 ▶ close RC
Branch: 1 branch
BranchTrueFalseTotal
close RC or $dbcgi->logconfess("load_config(): close failed for '${file}': $!") 0 0 0
284 or $dbcgi->logconfess("load_config(): close failed for '$file': $!");
285 0 ▶ my $data = JSON::from_json($buf,{utf8=>1,relaxed=>1})
Branch: 1 branch
BranchTrueFalseTotal
my $data = &JSON::from_json($buf, {"utf8", 1, "relaxed", 1}) or $dbcgi->logconfess("load_config(): from_json() failed for config data from '${file}': $!") 0 0 0
286 or $dbcgi->logconfess("load_config(): from_json() failed for config data from '$file': $!");
287 0 @$dbcgi{keys %$data} = values %$data;
288 0 return $dbcgi;
289 }
290  
291 ##======================================================================
292 ## Template Toolkit stuff
293  
294 ## $key = $dbcgi->ttk_key($key)
295 ## $key = $dbcgi->ttk_key()
296 ## + returns current template key
297 ## + default is basename($dbcgi->{prog}) without final extension
298 0 ▶sub ttk_key {
Subroutine ttk_key: not called CC=2 SCAR=17.9
Pod documented
299 0 my ($dbcgi,$key) = @_;
300 0 ▶ ($key=basename($dbcgi->{prog})) =~ s/\.[^\.]*\z// if (!$key);
Branch: 1 branch
BranchTrueFalseTotal
unless $key 0 0 0
301 0 return $key;
302 }
303  
304 ## @paths = $dbcgi->ttk_include()
305 ## $paths = $dbcgi->ttk_include()
306 ## + returns ttk search path @$dbcgi->{qw(ttk_dir ttk_sharedir)}
307 ## + in scalar context returns ":"-separated list
308 0 ▶sub ttk_include {
Subroutine ttk_include: not called CC=3 SCAR=24.8
Pod documented
309 0 my $dbcgi = shift;
310 0 ▶ my @dirs = map {s/\/+\z//; abs_path($_)} grep {defined($_) && $_ ne ''} @$dbcgi{qw(ttk_dir ttk_sharedir)};
Condition0%0/3
defined $_ && $_ ne ''
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && $_ ne ''
defined $_ $_ ne ''
Truth table0%0/3
A && B
A= defined $_B= $_ ne ''
ABresult
0X0
100
111
311 0 ▶ return wantarray ? @dirs : join(":",@dirs);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
312 }
313  
314 ## $file = $dbcgi->ttk_file()
315 ## $file = $dbcgi->ttk_file($key)
316 ## + returns template filename for template key (basename) $key
317 ## + $key defaults to $dbcgi->{prog} without final extension
318 ## + searches in $dbcgi->{ttk_dir} or $dbcgi->{ttk_sharedir}
319 0 ▶sub ttk_file {
Subroutine ttk_file: not called CC=4 SCAR=30.0
Pod documented
320 0 my ($dbcgi,$key) = @_;
321 0 ▶ (my $dir = $dbcgi->{ttk_dir} || '.') =~ s/\/+\z//;
Condition0%0/2
$dbcgi->{'ttk_dir'} || '.'
l!l
00
MC/DC0%0/1
$dbcgi->{'ttk_dir'} || '.'
$dbcgi->{'ttk_dir'}
Truth table0%0/2
A
A= $dbcgi->{'ttk_dir'}
Aresult
11
00
322 0 $key = $dbcgi->ttk_key($key);
323 0 my $file = "$key.ttk";
324 0 my @dirs = $dbcgi->ttk_include();
325 0 foreach (@dirs) {
326 0 ▶ return "$_/$file" if (-f "$_/$file");
Branch: 1 branch
BranchTrueFalseTotal
if -f "$_/$file" 0 0 0
327 }
328 0 $dbcgi->logconfess("ttk_file(): could not find template file '$file' in ttk search path ".$dbcgi->ttk_include);
329 }
330  
331 ## $t = $dbcgi->ttk_template(\%templateConfigArgs)
332 ## + returns a new Template object with default args set
333 0 ▶sub ttk_template {
Subroutine ttk_template: not called CC=3 SCAR=24.8
Pod documented
334 0 my ($dbcgi,$targs) = @_;
335 my $t = Template->new(
336 INTERPOLATE=>1,
337 PRE_CHOMP=>0,
338 POST_CHOMP=>1,
339 EVAL_PERL=>1,
340 ABSOLUTE=>1,
341 RELATIVE=>1,
342 INCLUDE_PATH =>scalar($dbcgi->ttk_include),
343 0 ▶ %{$dbcgi->{ttk_config}||{}},
Condition0%0/2
$dbcgi->{'ttk_config'} || {}
l!l
00
MC/DC0%0/1
$dbcgi->{'ttk_config'} || {}
$dbcgi->{'ttk_config'}
Truth table0%0/2
A
A= $dbcgi->{'ttk_config'}
Aresult
11
00
344 0 ▶ %{$targs||{}},
Condition0%0/2
$targs || {}
l!l
00
MC/DC0%0/1
$targs || {}
$targs
Truth table0%0/2
A
A= $targs
Aresult
11
00
345 );
346 0 return $t;
347 }
348  
349 ## $data = $dbcgi->ttk_process($srcFile, \%templateVars, \%templateConfigArgs, \%templateProcessArgs)
350 ## $dbcgi = $dbcgi->ttk_process($srcFile, \%templateVars, \%templateConfigArgs, \%templateProcessArgs, $outfh)
351 ## $dbcgi = $dbcgi->ttk_process($srcFile, \%templateVars, \%templateConfigArgs, \%templateProcessArgs, \$outbuf)
352 ## + process a template $srcFile, returns generated $data
353 0 ▶sub ttk_process {
Subroutine ttk_process: not called CC=8 SCAR=42.8
Pod documented
354 0 my ($dbcgi,$src,$tvars,$targs,$pargs,$output) = @_;
355 0 my $outbuf = '';
356 0 my $t = $dbcgi->ttk_template($targs);
357 $t->process($src,
358 0 ▶ {package=>$dbcgi->{ttk_package}, version=>$VERSION, ENV=>{%ENV}, %{$dbcgi->{ttk_vars}||{}}, cdb=>$dbcgi, %{$tvars||{}}},
Branch: 1 branch
BranchTrueFalseTotal
defined $output ? : 0 0 0
Condition0%0/4
$dbcgi->{'ttk_vars'} || {}
l!l
00
$tvars || {}
l!l
00
MC/DC0%0/1
$dbcgi->{'ttk_vars'} || {}
$dbcgi->{'ttk_vars'}
MC/DC0%0/1
$tvars || {}
$tvars
Truth table0%0/2
A
A= $dbcgi->{'ttk_vars'}
Aresult
11
00
Truth table0%0/2
A
A= $tvars
Aresult
11
00
359 (defined($output) ? $output : \$outbuf),
360 0 ▶ %{$dbcgi->{ttk_process}||{}},
Condition0%0/2
$dbcgi->{'ttk_process'} || {}
l!l
00
MC/DC0%0/1
$dbcgi->{'ttk_process'} || {}
$dbcgi->{'ttk_process'}
Truth table0%0/2
A
A= $dbcgi->{'ttk_process'}
Aresult
11
00
361 0 ▶ %{$pargs||{}},
Branch: 1 branch
BranchTrueFalseTotal
$t->process($src, {"package", $dbcgi->{"ttk_package"}, "version", $DiaColloDB::WWW::CGI::VERSION, "ENV", {%ENV}, %{$dbcgi->{"ttk_vars"} or {};}, "cdb", $dbcgi, %{$tvars or {};}}, defined $output ? $output : \$outbuf, %{$dbcgi->{"ttk_process"} or {};}, %{$pargs or {};}) or $dbcgi->logconfess('ttk_process(): template error: ' . $t->error) 0 0 0
Condition0%0/2
$pargs || {}
l!l
00
MC/DC0%0/1
$pargs || {}
$pargs
Truth table0%0/2
A
A= $pargs
Aresult
11
00
362 )
363 or $dbcgi->logconfess("ttk_process(): template error: ".$t->error);
364 0 ▶ return defined($output) ? $dbcgi : $outbuf;
Branch: 1 branch
BranchTrueFalseTotal
defined $output ? : 0 0 0
365 }
366  
367 ##======================================================================
368 ## CGI stuff: generic
369  
370 ## @error = $dbcgi->htmlerror($status,@message)
371 ## + returns a print()-able HTML error
372 0 ▶sub htmlerror {
Subroutine htmlerror: not called CC=3 SCAR=24.8
Pod documented
373 0 my ($dbcgi,$status,@msg) = @_;
374 0 ▶ $status = 500 if (!defined($status)); ##-- RC_INTERNAL_SERVER_ERROR
Branch: 1 branch
BranchTrueFalseTotal
unless defined $status 0 0 0
375 0 my $title = 'Error: '.$status.' '.status_message($status);
376 0 charset($dbcgi->{charset});
377 0 ▶ my $msg = join(($,//''), @msg);
Condition0%0/2
$, // ""
l!l
00
MC/DC0%0/1
$, // ""
$,
Truth table0%0/2
A
A= $,
Aresult
11
00
378 0 $msg =~ s/\beval\s*\'(?:\\.|[^\'])*\'/eval '...'/sg; ##-- suppress long eval '...' messsages
379 return
380 0 (header(-status=>$status),
381 start_html($title),
382 h1($title),
383 pre("\n",escapeHTML($msg),"\n"),
384 end_html,
385 );
386 }
387  
388 ## @whatever = $dbcgi->cgi($method, @args)
389 ## + call a method from the CGI package $dbcgi->{cgipkg}->can($method)
390 0 ▶sub cgi {
Subroutine cgi: not called CC=5 SCAR=34.0
Pod documented
391 0 my ($dbcgi,$method)=splice(@_,0,2);
392 0 ▶ CGI::charset($dbcgi->{charset}) if ($dbcgi->{charset});
Branch: 1 branch
BranchTrueFalseTotal
if $dbcgi->{"charset"} 0 0 0
393 0 my ($sub);
394 0 ▶ if (ref($method)) {
Branch: 3 branches
BranchTrueFalseTotal
if (ref $method) { } 0 0 0
elsif ($sub = $dbcgi->{'cgipkg'}->can($method)) { } 0 0 0
elsif ($sub = 'CGI'->can($method)) { } 0 0 0
395 0 return $method->(@_);
396 }
397 elsif ($sub=$dbcgi->{cgipkg}->can($method)) {
398 0 return $sub->(@_);
399 }
400 elsif ($sub=CGI->can($method)) {
401 0 return $sub->(@_);
402 }
403 0 $dbcgi->logconfess("cgi(): unknown method '$method' for cgipkg='$dbcgi->{cgipkg}'");
404 }
405  
406 ## undef = $dbcgi->cgi_main()
407 ## undef = $dbcgi->cgi_main($ttk_key)
408 ## + wraps a template-instantiation for $ttk_key, by default basename($0)
409 0 ▶sub cgi_main {
Subroutine cgi_main: not called CC=8 SCAR=42.8
Pod documented
410 0 my ($dbcgi,$key) = @_;
411 0 my @content;
412 0 my $israw = $dbcgi->{ttk_rawkeys}{$dbcgi->ttk_key($key)};
413 0 eval {
414 0 ▶ @content = $dbcgi->ttk_process($dbcgi->ttk_file($key), $dbcgi->vars, ($israw ? {ENCODING=>undef} : undef), ($israw ? {binmode=>':raw'} : undef));
Branch: 2 branches
BranchTrueFalseTotal
$israw ? : 0 0 0
$israw ? : 0 0 0
415 };
416 0 ▶ if ($@) {
Branch: 2 branches
BranchTrueFalseTotal
if ($@) { } 0 0 0
elsif (not @content && defined $content[0]) { } 0 0 0
417 0 $israw = 0;
418 0 @content = $dbcgi->htmlerror(undef, $@);
419 }
420 ▶ elsif (!@content || !defined($content[0])) {
Condition0%0/3
@content && defined $content[0]
!ll&&!rl&&r
000
MC/DC0%0/2
@content && defined $content[0]
@content defined $content[0]
Truth table0%0/3
A && B
A= @contentB= defined $content[0]
ABresult
0X0
100
111
421 0 $israw = 0;
422 0 @content = $dbcgi->htmlerror(undef, "template '$key' returned no content");
423 }
424  
425 0 ▶ if ($dbcgi->{charset}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dbcgi->{"charset"}) 0 0 0
426 0 charset($dbcgi->{charset});
427 0 ▶ binmode(\*STDOUT, ($israw ? ":raw" : ":encoding($dbcgi->{charset})"));
Branch: 1 branch
BranchTrueFalseTotal
$israw ? : 0 0 0
428 }
429 0 print @content;
430 }
431  
432 ## undef = $dbcgi->fcgi_main()
433 ## undef = $dbcgi->fcgi_main($ttk_key)
434 ## + wraps a template-instantiation for $ttk_key, by default basename($0)
435 0 ▶sub fcgi_main {
Subroutine fcgi_main: not called CC=2 SCAR=17.9
Pod documented
436 0 my ($dbcgi,$key) = @_;
437 0 require CGI::Fast;
438 0 CGI::Fast->import(':standard');
439 0 $dbcgi->{cgipkg} = 'CGI::Fast';
440 0 ▶ while (CGI::Fast->new()) {
Branch: 1 branch
BranchTrueFalseTotal
if ("CGI::Fast"->new) 0 0 0
441 0 $dbcgi->_getenv();
442 0 $dbcgi->cgi_main($key);
443 0 $dbcgi->_reset();
444 }
445 }
446  
447 ##======================================================================
448 ## Template stuff: useful aliases
449  
450 0 ▶sub remoteAddr { return $_[0]{remote_addr}; }
Subroutine remoteAddr: not called CC=1 SCAR=6.9
Pod documented
451 0 ▶sub remoteUser { return $_[0]{remote_user}; }
Subroutine remoteUser: not called CC=1 SCAR=6.9
Pod documented
452 0 ▶sub requestMethod { return $_[0]{request_method}; }
Subroutine requestMethod: not called CC=1 SCAR=6.9
Pod documented
453 0 ▶sub requestUri { return $_[0]{request_uri}; }
Subroutine requestUri: not called CC=1 SCAR=6.9
Pod documented
454 0 ▶sub requestQuery { return $_[0]{request_query}; }
Subroutine requestQuery: not called CC=1 SCAR=6.9
Pod documented
455 0 ▶sub httpReferer { return $_[0]{http_referer}; }
Subroutine httpReferer: not called CC=1 SCAR=6.9
Pod documented
456 0 ▶sub httpHost { return $_[0]{http_host}; }
Subroutine httpHost: not called CC=1 SCAR=6.9
Pod documented
457 0 ▶sub serverAddr { return $_[0]{server_addr}; }
Subroutine serverAddr: not called CC=1 SCAR=6.9
Pod documented
458 0 ▶sub serverPort {
Subroutine serverPort: not called CC=5 SCAR=34.0
Pod documented
459 0 ▶ return $_[0]{server_port} if ($_[0]{server_port});
Branch: 1 branch
BranchTrueFalseTotal
if $_[0]{"server_port"} 0 0 0
460 0 my $host = $_[0]->httpHost;
461 0 ▶ return $1 if ($host && $host =~ /:([0-9]+)$/);
Branch: 1 branch
BranchTrueFalseTotal
if $host and $host =~ /:([0-9]+)$/ 0 0 0
Condition0%0/3
$host and $host =~ /:([0-9]+)$/
!ll&&!rl&&r
000
MC/DC0%0/2
$host and $host =~ /:([0-9]+)$/
$host $host =~ /:([0-9]+)$/
Truth table0%0/3
A and B
A= $hostB= $host =~ /:([0-9]+)$/
ABresult
0X0
100
111
462 0 ▶ return $ENV{HTTPS} ? 443 : 80; ##-- guess port from scheme
Branch: 1 branch
BranchTrueFalseTotal
$ENV{'HTTPS'} ? : 0 0 0
463 }
464  
465  
466 ## $uri = $dbcgi->uri()
467 ## $uri = $dbcgi->uri($uri)
468 0 ▶sub uri {
Subroutine uri: not called CC=9 SCAR=45.0
Pod documented
469 0 ▶ return URI->new($_[1]) if (defined $_[1]);
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[1] 0 0 0
470 0 my $dbcgi = shift;
471 0 ▶ my $host = $dbcgi->httpHost // '';
Condition0%0/2
$dbcgi->httpHost // ""
l!l
00
MC/DC0%0/1
$dbcgi->httpHost // ""
$dbcgi->httpHost
Truth table0%0/2
A
A= $dbcgi->httpHost
Aresult
11
00
472 0 my $port = $dbcgi->serverPort;
473 0 ▶ my $scheme = ($ENV{HTTPS} ? 'https' : 'http');
Branch: 1 branch
BranchTrueFalseTotal
$ENV{'HTTPS'} ? : 0 0 0
474 0 ▶ return URI->new(
Branch: 3 branches
BranchTrueFalseTotal
$host ? : 0 0 0
$host && $host =~ /:[0-9]+$/ || $port == ($scheme eq 'https' ? 443 : 80) ? : 0 0 0
$scheme eq 'https' ? : 0 0 0
Condition0%0/6
$host and $host =~ /:[0-9]+$/ or $port == ($scheme eq "https" ? 443 : 80)
l!l&&r!l&&!r
000
$host and $host =~ /:[0-9]+$/
!ll&&!rl&&r
000
MC/DC0%0/3
$host and $host =~ /:[0-9]+$/ or $port == ($scheme eq "https" ? 443 : 80)
$host $host =~ /:[0-9]+$/ $port == ($scheme eq "https" ? 443 : 80)
Truth table0%0/5
A and B or C
A= $hostB= $host =~ /:[0-9]+$/C= $port == ($scheme eq "https" ? 443 : 80)
ABCresult
11X1
0X11
1011
0X00
1000
475 #($host ? "http://$host" : "file://")
476 ($host ? "${scheme}://$host" : "file://") ##-- guess scheme from HTTPS environment variable
477 .( ($host && $host =~ /:[0-9]+$/) || $port==($scheme eq 'https' ? 443 : 80) ? '' : ":$port" )
478 .$dbcgi->requestUri
479 );
480 }
481  
482 ## $scheme = $dbcgi->uriScheme($uri?)
483 ## $opaque = $dbcgi->uriOpaque($uri?)
484 ## $path = $dbcgi->uriPath($uri?)
485 ## $frag = $dbcgi->uriFragment($uri?)
486 ## $canon = $dbcgi->uriCanonical($uri?)
487 ## $abs = $dbcgi->uriAbs($uri?);
488 0 ▶sub uriScheme { $_[0]->uri($_[1])->scheme; }
Subroutine uriScheme: not called CC=1 SCAR=6.9
Pod documented
489 0 ▶sub uriPath { $_[0]->uri($_[1])->path; }
Subroutine uriPath: not called CC=1 SCAR=6.9
Pod documented
490 0 ▶sub uriFragment { $_[0]->uri($_[1])->fragment; }
Subroutine uriFragment: not called CC=1 SCAR=6.9
Pod documented
491 0 ▶sub uriCanonical { $_[0]->uri($_[1])->canonical->as_string; }
Subroutine uriCanonical: not called CC=1 SCAR=6.9
Pod documented
492 0 ▶sub uriAbs { $_[0]->uri($_[1])->abs->as_string; }
Subroutine uriAbs: not called CC=1 SCAR=6.9
Pod documented
493  
494 ## $dir = $dbcgi->uriDir($uri?)
495 ## + returns URI up to but not including query or fragment, truncating any trailing slashes
496 0 ▶sub uriDir {
Subroutine uriDir: not called CC=1 SCAR=6.9
Pod documented
497 0 my $uri = $_[0]->uri($_[1])->as_string;
498 0 $uri =~ s{[?#].*$}{};
499 0 $uri =~ s{/+[^/]*$}{};
500 0 return $uri;
501 }
502  
503 ## $auth = $dbcgi->uriAuthority($uri?)
504 ## $pquery = $dbcgi->uriPathQuery($uri?)
505 ## \@segs = $dbcgi->uriPathSegments($uri?)
506 ## $query = $dbcgi->uriQuery($uri?)
507 ## \%form = $dbcgi->uriQueryForm($uri?)
508 ## \@kws = $dbcgi->uriQueryKeywords($uri?)
509 0 ▶sub uriAuthority { $_[0]->uri($_[1])->authority; }
Subroutine uriAuthority: not called CC=1 SCAR=6.9
Pod documented
510 0 ▶sub uriPathQuery { $_[0]->uri($_[1])->path_query; }
Subroutine uriPathQuery: not called CC=1 SCAR=6.9
Pod documented
511 0 ▶sub uriPathSegments { [$_[0]->uri($_[1])->path_segments]; }
Subroutine uriPathSegments: not called CC=1 SCAR=6.9
Pod documented
512 0 ▶sub uriQuery { $_[0]->uri($_[1])->query; }
Subroutine uriQuery: not called CC=1 SCAR=6.9
Pod documented
513 0 ▶sub uriQueryForm { {$_[0]->uri($_[1])->query_form}; }
Subroutine uriQueryForm: not called CC=1 SCAR=6.9
Pod documented
514 0 ▶sub uriQueryKeywords { [$_[0]->uri($_[1])->query_keywords]; }
Subroutine uriQueryKeywords: not called CC=1 SCAR=6.9
Pod documented
515  
516 ## $userinfo = $dbcgi->uriUserInfo($uri?)
517 ## $host = $dbcgi->uriHost($uri?)
518 ## $port = $dbcgi->uriPort($uri?)
519 0 ▶sub userinfo { $_[0]->uri($_[1])->userinfo; }
Subroutine userinfo: not called CC=1 SCAR=6.9
Pod documented
520 0 ▶sub uriHost { $_[0]->uri($_[1])->host; }
Subroutine uriHost: not called CC=1 SCAR=6.9
Pod documented
521 0 ▶sub uriPort { $_[0]->uri($_[1])->port; }
Subroutine uriPort: not called CC=1 SCAR=6.9
Pod documented
522  
523 ## $uristr = quri($base, \%form)
524 0 ▶sub quri {
Subroutine quri: not called CC=4 SCAR=30.0
Pod documented
525 0 ▶ shift if (isa($_[0],__PACKAGE__));
Branch: 1 branch
BranchTrueFalseTotal
if DiaColloDB::WWW::CGI::isa($_[0], __PACKAGE__) 0 0 0
526 0 my ($base,$form)=@_;
527 0 my $uri=URI->new($base);
528 0 ▶ $uri->query_form($uri->query_form, map {utf8::is_utf8($_) ? Encode::encode_utf8($_) : $_} %{$form||{}});
Branch: 1 branch
BranchTrueFalseTotal
utf8::is_utf8($_) ? : 0 0 0
Condition0%0/2
$form || {}
l!l
00
MC/DC0%0/1
$form || {}
$form
Truth table0%0/2
A
A= $form
Aresult
11
00
529 0 return $uri->as_string;
530 }
531  
532 ## $urisub = uuri($base, \%form)
533 ## $uristr = $urisub->(\%form)
534 0 ▶sub uuri {
Subroutine uuri: not called CC=2 SCAR=17.9
Pod documented
535 0 ▶ shift if (isa($_[0],__PACKAGE__));
Branch: 1 branch
BranchTrueFalseTotal
if DiaColloDB::WWW::CGI::isa($_[0], __PACKAGE__) 0 0 0
536 0 my $qbase = quri(@_);
537 0 ▶ return sub { quri($qbase,@_); };
Subroutine __ANON__: not called CC=1 SCAR=6.9
538 }
539  
540 ## $sqstring = sqstring($str)
541 0 ▶sub sqstring {
Subroutine sqstring: not called CC=2 SCAR=17.9
Pod documented
542 0 ▶ shift if (isa($_[0],__PACKAGE__));
Branch: 1 branch
BranchTrueFalseTotal
if DiaColloDB::WWW::CGI::isa($_[0], __PACKAGE__) 0 0 0
543 0 (my $s=shift) =~ s/([\\\'])/\\$1/g; "'$s'"
544 }
545  
546 ## $str = sprintf_(...)
547 0 ▶sub sprintf_ {
Subroutine sprintf_: not called CC=2 SCAR=17.9
Pod documented
548 0 ▶ shift if (isa($_[0],__PACKAGE__));
Branch: 1 branch
BranchTrueFalseTotal
if DiaColloDB::WWW::CGI::isa($_[0], __PACKAGE__) 0 0 0
549 0 return CORE::sprintf($_[0],@_[1..$#_]);
550 }
551  
552 ## $mtime = $dbcgi->mtime($filename)
553 0 ▶sub mtime {
Subroutine mtime: not called CC=2 SCAR=17.9
Pod documented
554 0 my $dbcgi = shift;
555 0 my $file = shift;
556 0 ▶ $file =~ s/^.*?=(\w+).*$/$1/ if ($file =~ /^dbi:/); ##-- trim dsns
Branch: 1 branch
BranchTrueFalseTotal
if $file =~ /^dbi:/ 0 0 0
557 0 my @stat = stat($file);
558 0 return $stat[9];
559 }
560  
561 ## $str = $dbcgi->timestamp()
562 ## + gets localtime timestamp
563 0 ▶sub timestamp {
Subroutine timestamp: not called CC=1 SCAR=6.9
Pod documented
564 #my $dbcgi = shift;
565 0 return POSIX::strftime('%Y-%m-%d %H:%M:%S', localtime());
566 }
567  
568 ## $json_str = PACKAGE->to_json($data)
569 ## $json_str = PACKAGE::to_json($data)
570 ## $json_str = PACKAGE->to_json($data,\%opts)
571 ## $json_str = PACKAGE::to_json($data,\%opts)
572 0 ▶sub to_json {
Subroutine to_json: not called CC=3 SCAR=24.8
Pod documented
573 0 ▶ shift if (isa($_[0],__PACKAGE__));
Branch: 1 branch
BranchTrueFalseTotal
if DiaColloDB::WWW::CGI::isa($_[0], __PACKAGE__) 0 0 0
574 0 ▶ return JSON::to_json($_[0]) if (@_==1);
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 1 0 0 0
575 0 return JSON::to_json($_[0],$_[1]);
576 }
577  
578 ## $json_str = PACKAGE->from_json($data)
579 ## $json_str = PACKAGE::from_json($data)
580 0 ▶sub from_json {
Subroutine from_json: not called CC=2 SCAR=17.9
Pod documented
581 0 ▶ shift if (isa($_[0],__PACKAGE__));
Branch: 1 branch
BranchTrueFalseTotal
if DiaColloDB::WWW::CGI::isa($_[0], __PACKAGE__) 0 0 0
582 0 return JSON::from_json(@_);
583 }
584  
585 ## \@timeofday = PACKAGE->gettimeofday()
586 ## \@timeofday = PACKAGE::gettimeofday()
587 0 ▶sub gettimeofday {
Subroutine gettimeofday: not called CC=2 SCAR=17.9
Pod documented
588 0 ▶ shift if (isa($_[0],__PACKAGE__));
Branch: 1 branch
BranchTrueFalseTotal
if DiaColloDB::WWW::CGI::isa($_[0], __PACKAGE__) 0 0 0
589 0 return [Time::HiRes::gettimeofday()];
590 }
591  
592 ## $secs = PACKAGE->tv_interval($t0,$t1)
593 ## $secs = PACKAGE::tv_interval($t0,$t1)
594 0 ▶sub tv_interval {
Subroutine tv_interval: not called CC=2 SCAR=17.9
Pod documented
595 0 ▶ shift if (isa($_[0],__PACKAGE__));
Branch: 1 branch
BranchTrueFalseTotal
if DiaColloDB::WWW::CGI::isa($_[0], __PACKAGE__) 0 0 0
596 0 return Time::HiRes::tv_interval(@_);
597 }
598  
599 ## \@timeofday = PACKAGE->t_start()
600 ## \@timeofday = PACKAGE->t_start()
601 ## + sets package variable $t_started
602 1 our $t_started = [Time::HiRes::gettimeofday];
603 0 ▶sub t_start {
Subroutine t_start: not called CC=2 SCAR=17.9
Pod documented
604 0 ▶ shift if (isa($_[0],__PACKAGE__));
Branch: 1 branch
BranchTrueFalseTotal
if DiaColloDB::WWW::CGI::isa($_[0], __PACKAGE__) 0 0 0
605 0 $t_started = [Time::HiRes::gettimeofday];
606 }
607  
608 ## $secs = PACKAGE->t_elapsed()
609 ## $secs = PACKAGE->t_elapsed($t1)
610 ## $secs = PACKAGE->t_elapsed($t0,$t1)
611 ## $secs = PACKAGE::t_elapsed()
612 ## $secs = PACKAGE::t_elapsed($t1)
613 ## $secs = PACKAGE::t_elapsed($t0,$t1)
614 0 ▶sub t_elapsed {
Subroutine t_elapsed: not called CC=4 SCAR=30.0
Pod documented
615 0 ▶ shift if (isa($_[0],__PACKAGE__));
Branch: 1 branch
BranchTrueFalseTotal
if DiaColloDB::WWW::CGI::isa($_[0], __PACKAGE__) 0 0 0
616 0 my ($t0,$t1) = @_;
617 0 ▶ return tv_interval($t_started,[Time::HiRes::gettimeofday]) if (!@_);
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 0 0
618 0 ▶ return tv_interval($t_started,$_[0]) if (@_==1);
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 1 0 0 0
619 0 return tv_interval($_[0],$_[1]);
620 }
621  
622 ## $enc = PACKAGE->encode_utf8($str, $force=0)
623 ## $enc = PACKAGE::encode_utf8($str, $force=0)
624 ## + encodes only if $force is true or if not already flagged as a byte-string
625 0 ▶sub encode_utf8 {
Subroutine encode_utf8: not called CC=4 SCAR=30.0
Pod documented
626 0 ▶ shift if (isa($_[0],__PACKAGE__));
Branch: 1 branch
BranchTrueFalseTotal
if DiaColloDB::WWW::CGI::isa($_[0], __PACKAGE__) 0 0 0
627 0 ▶ return $_[0] if (!$_[1] && !utf8::is_utf8($_[0]));
Branch: 1 branch
BranchTrueFalseTotal
unless $_[1] or utf8::is_utf8($_[0]) 0 0 0
Condition0%0/3
$_[1] or utf8::is_utf8($_[0])
l!l&&r!l&&!r
000
MC/DC0%0/2
$_[1] or utf8::is_utf8($_[0])
$_[1] utf8::is_utf8($_[0])
Truth table0%0/3
A or B
A= $_[1]B= utf8::is_utf8($_[0])
ABresult
1X1
011
000
628 0 return Encode::encode_utf8($_[0]);
629 }
630  
631 ## $enc = PACKAGE->decode_utf8($str, $force=0)
632 ## $enc = PACKAGE::decode_utf8($str, $force=0)
633 ## + decodes only if $force is true or if not flagged as a byte-string
634 0 ▶sub decode_utf8 {
Subroutine decode_utf8: not called CC=4 SCAR=30.0
Pod documented
635 0 ▶ shift if (isa($_[0],__PACKAGE__));
Branch: 1 branch
BranchTrueFalseTotal
if DiaColloDB::WWW::CGI::isa($_[0], __PACKAGE__) 0 0 0
636 0 ▶ return $_[0] if (!$_[1] && utf8::is_utf8($_[0]));
Branch: 1 branch
BranchTrueFalseTotal
if not $_[1] and utf8::is_utf8($_[0]) 0 0 0
Condition0%0/3
not $_[1] and utf8::is_utf8($_[0])
!ll&&!rl&&r
000
MC/DC0%0/2
not $_[1] and utf8::is_utf8($_[0])
not $_[1] utf8::is_utf8($_[0])
Truth table0%0/3
not(A) and B
A= not $_[1]B= utf8::is_utf8($_[0])
ABresult
0X0
100
111
637 0 return Encode::decode_utf8($_[0]);
638 }
639  
640 1 1; ##-- be happy
641  
642 __END__
« WWW/Server.pm ↑ Summary WWW/Handler.pm »