Klonk/Env.pm

filter: Statementstmt 21.3% 16 / 75 Branchbran 0.0% 0 / 36 Conditioncond 0.0% 0 / 10 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 33.3% 3 / 9 Podpod 100% 4 / 4 totaltotal 16.5% 23 / 139 CC 25 SCAR 44.2
CC
25
Cov
13%
new
182.0
_parse_query
42.0
vpath
12.0
CRAP 83.0
« Klonk/Routes.pm ↑ Summary Klonk/Handle.pm »
1 package Klonk::Env 0.01;
2 1 ▶use Klonk::pragma;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use Unicode::UTF8 qw(decode_utf8);
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 MAX_FORM_BODY_SIZE => 10 * 1024 * 1024,
7 1 };
8  
9 0 ▶fun _parse_query($query_string) {
Subroutine _parse_query: not called CC=6 SCAR=37.4
Branch: 2 branches
BranchTrueFalseTotal
@_ < 1 and Function::Parameters::_croak('Too few arguments for fun _parse_query (expected 1, got ' . @_ . ')') 0 0 0
@_ > 1 and Function::Parameters::_croak('Too many arguments for fun _parse_query (expected 1, got ' . @_ . ')') 0 0 0
10 0 my %param;
11 0 for my $kv (split /&/, $query_string) {
12 0 my ($k, $v) = split /=/, $kv, 2;
13 0 for ($k, $v) {
14 0 ▶ defined or next;
Branch: 1 branch
BranchTrueFalseTotal
defined $_ or next 0 0 0
15 0 tr/+/ /;
16 0 s/%([[:xdigit:]]{2})/chr hex $1/eg;
17 0 $_ = decode_utf8 $_;
18 }
19 0 $param{$k} = $v;
20 }
21 0 \%param
22 1 }
23  
24 0 ▶method new($class: $env) {
Subroutine new: not called CC=13 SCAR=52.0
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
@_ < 2 and Function::Parameters::_croak('Too few arguments for method new (expected 2, got ' . @_ . ')') 0 0 0
@_ > 2 and Function::Parameters::_croak('Too many arguments for method new (expected 2, got ' . @_ . ')') 0 0 0
25 0 my $qparam = _parse_query $env->{QUERY_STRING};
26  
27 0 my $bparam = {};
28 {
29 0 my $verb = $env->{REQUEST_METHOD};
30 0 ▶ if ($verb eq 'POST' || $verb eq 'PUT' || $verb eq 'PATCH') {
Branch: 1 branch
BranchTrueFalseTotal
if ($verb eq "POST" or $verb eq "PUT" or $verb eq "PATCH") 0 0 0
Condition0%0/6
$verb eq "POST" or $verb eq "PUT" or $verb eq "PATCH"
l!l&&r!l&&!r
000
$verb eq "POST" or $verb eq "PUT"
l!l&&r!l&&!r
000
MC/DC0%0/3
$verb eq "POST" or $verb eq "PUT" or $verb eq "PATCH"
$verb eq "POST" $verb eq "PUT" $verb eq "PATCH"
Truth table0%0/4
A or B or C
A= $verb eq "POST"B= $verb eq "PUT"C= $verb eq "PATCH"
ABCresult
1XX1
01X1
0011
0000
31 0 ▶ my $ctype = $env->{CONTENT_TYPE} // '';
Condition0%0/2
$env->{"CONTENT_TYPE"} // ""
l!l
00
MC/DC0%0/1
$env->{"CONTENT_TYPE"} // ""
$env->{"CONTENT_TYPE"}
Truth table0%0/2
A
A= $env->{"CONTENT_TYPE"}
Aresult
11
00
32 0 ▶ my $clength = $env->{CONTENT_LENGTH} // 0;
Condition0%0/2
$env->{"CONTENT_LENGTH"} // 0
l!l
00
MC/DC0%0/1
$env->{"CONTENT_LENGTH"} // 0
$env->{"CONTENT_LENGTH"}
Truth table0%0/2
A
A= $env->{"CONTENT_LENGTH"}
Aresult
11
00
33 0 ▶ $clength <= MAX_FORM_BODY_SIZE
Branch: 1 branch
BranchTrueFalseTotal
$clength <= 10485760 or die "Request size ($clength) exceeds maximum form size" 0 0 0
34 or die "Request size ($clength) exceeds maximum form size";
35 0 ▶ if ($ctype eq 'application/x-www-form-urlencoded') {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctype eq "application/x-www-form-urlencoded") 0 0 0
36 0 my $input = $env->{'psgi.input'};
37 0 my $query = '';
38 0 ▶ while ((my $d = $clength - length($query)) > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ((my $d = $clength - length($query)) > 0) 0 0 0
39 0 ▶ my $n = $input->read($query, $d, length($query))
Branch: 1 branch
BranchTrueFalseTotal
my $n = $input->read($query, $d, length $query) and next 0 0 0
40 and next;
41 0 ▶ defined $n
Branch: 1 branch
BranchTrueFalseTotal
defined $n and die "Premature end of request body (received ${\length($query);} of $clength bytes)" 0 0 0
42 0 and die "Premature end of request body (received ${\length $query} of $clength bytes)";
43 0 die "Error while reading request body: $!";
44 }
45 0 $bparam = _parse_query $query;
46 }
47 }
48 }
49  
50 bless {
51 0 %$env,
52 'klonk.qparam' => $qparam,
53 'klonk.bparam' => $bparam,
54 }, $class
55 1 }
56  
57 0 ▶method DESTROY(@) {}
Subroutine DESTROY: not called CC=2 SCAR=14.6
Branch: 1 branch
BranchTrueFalseTotal
@_ < 1 and Function::Parameters::_croak('Too few arguments for method DESTROY (expected 1, got ' . @_ . ')') 0 0 0
58  
59 0 ▶method vpath($path) {
Subroutine vpath: not called CC=3 SCAR=24.8
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
@_ < 2 and Function::Parameters::_croak('Too few arguments for method vpath (expected 2, got ' . @_ . ')') 0 0 0
@_ > 2 and Function::Parameters::_croak('Too many arguments for method vpath (expected 2, got ' . @_ . ')') 0 0 0
60 0 $self->{SCRIPT_NAME} . '/' . $path =~ s!^/!!r
61 1 }
62  
63 0 ▶method qparam($k) {
Subroutine qparam: not called CC=3 SCAR=24.8
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
@_ < 2 and Function::Parameters::_croak('Too few arguments for method qparam (expected 2, got ' . @_ . ')') 0 0 0
@_ > 2 and Function::Parameters::_croak('Too many arguments for method qparam (expected 2, got ' . @_ . ')') 0 0 0
64 0 $self->{'klonk.qparam'}{$k}
65 1 }
66  
67 0 ▶method bparam($k) {
Subroutine bparam: not called CC=3 SCAR=24.8
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
@_ < 2 and Function::Parameters::_croak('Too few arguments for method bparam (expected 2, got ' . @_ . ')') 0 0 0
@_ > 2 and Function::Parameters::_croak('Too many arguments for method bparam (expected 2, got ' . @_ . ')') 0 0 0
68 0 $self->{'klonk.bparam'}{$k}
69 1 }
70  
71 1 1
72 __END__
« Klonk/Routes.pm ↑ Summary Klonk/Handle.pm »