blib/lib/Lemonldap/NG/Common/PSGI/Request.pm

filter: Statementstmt 52.6% 40 / 76 Branchbran 25.0% 5 / 20 Conditioncond 26.6% 4 / 15 MC/DCmcdc 11.1% 1 / 9 Subroutinesub 32.0% 8 / 25 Podpod 75.0% 15 / 20 totaltotal 44.2% 73 / 165 CC 18 SCAR 19.8
CC
18
Cov
44%
BUILD
20.0
userData
20.0
wantJSON
12.0
CRAP 7.2
« blib/lib/Lemonldap/NG/Common/Conf/Backends/_DBI.pm ↑ Summary blib/lib/Lemonldap/NG/Common/PSGI/Cli/Lib.pm »
1 package Lemonldap::NG::Common::PSGI::Request;
2  
3 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 8 ▶use Mouse;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 8 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 8 ▶use Plack::Request;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 8 ▶use URI::Escape;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 8 our $VERSION = '2.19.0';
10  
11 8 our @ISA = ('Plack::Request');
12  
13 # http :// server / path ? query # fragment
14 # m|(?:([^:/?#]+):)?(?://([^/?#]*))?([^?#]*)(?:\?([^#]*))?(?:#(.*))?|;
15  
16 sub BUILD {
17 0 ▶ my ( $self, $env ) = @_;
Subroutine BUILD: not called CC=4 SCAR=30.0
Pod undocumented
18 0 foreach ( keys %$env ) {
19 0 ▶ $self->{$_} ||= $env->{$_} if (/^(?:HTTP|SSL)_/);
Branch: 1 branch
BranchTrueFalseTotal
if /^(?:HTTP|SSL)_/ 0 0 0
Condition0%0/3
$self->{$_} ||= $env->{$_}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{$_} ||= $env->{$_}
$self->{$_} $env->{$_}
Truth table0%0/3
A ||= B
A= $self->{$_}B= $env->{$_}
ABresult
1X1
011
000
20 }
21 }
22  
23 sub new {
24 13 ▶ my $self = Plack::Request::new(@_);
Subroutine new: called CC=4 SCAR=13.9
Pod documented
25 $self->env->{REQUEST_URI} = $self->env->{X_ORIGINAL_URI}
26 13 ▶ if ( $self->env->{X_ORIGINAL_URI} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->env->{"X_ORIGINAL_URI"} 0 13 13
27 13 $self->env->{PATH_INFO} =~ s|//+|/|g;
28 13 ▶ $self->env->{PATH_INFO} ||= '/';
Condition100%2/2
$self->env->{"PATH_INFO"} ||= "/"
l!l
121
MC/DC100%1/1
$self->env->{"PATH_INFO"} ||= "/"
$self->env->{"PATH_INFO"}
Truth table100%2/2
A
A= $self->env->{"PATH_INFO"}
Aresult
11
00
29 13 $self->env->{REQUEST_URI} =~ s|^//+|/|g;
30 13 $self->{uri} = uri_unescape( $self->env->{REQUEST_URI} );
31 13 $self->{data} = {};
32 $self->{request_id} = ( $self->env->{UNIQUE_ID}
33 13 ▶ || join( '', map { [ 0 .. 9, "a" .. "f" ]->[ rand 16 ] } 1 .. 16 ) );
Condition66%2/3
$self->env->{'UNIQUE_ID'} || join('', map({[0..9, ('a', 'b', 'c', 'd', 'e', 'f')]->[rand 16];} 1..16))
l!l&&r!l&&!r
2110
MC/DC0%0/2
$self->env->{'UNIQUE_ID'} || join('', map({[0..9, ('a', 'b', 'c', 'd', 'e', 'f')]->[rand 16];} 1..16))
$self->env->{'UNIQUE_ID'} join('', map({[0..9, ('a', 'b', 'c', 'd', 'e', 'f')]->[rand 16];} 1..16))
Truth table66%2/3
A || B
A= $self->env->{'UNIQUE_ID'}B= join('', map({[0..9, ('a', 'b', 'c', 'd', 'e', 'f')]->[rand 16];} 1..16))
ABresult
1X1
011
000
34 13 $self->{error} = 0;
35 13 $self->{respHeaders} = [];
36 13 return bless( $self, $_[0] );
37 }
38  
39 0 ▶sub data { return $_[0]->{data} }
Subroutine data: not called CC=1 SCAR=6.9
Pod undocumented
40  
41 0 ▶sub uri { return $_[0]->{uri} }
Subroutine uri: not called CC=1 SCAR=6.9
Pod documented
42  
43 13 ▶sub request_id { return $_[0]->{request_id} }
Subroutine request_id: called CC=1 SCAR=0.0
Pod undocumented
44  
45 sub userData {
46 0 ▶ my ( $self, $v ) = @_;
Subroutine userData: not called CC=4 SCAR=30.0
Pod documented
47 0 ▶ return $self->{userData} = $v if ($v);
Branch: 1 branch
BranchTrueFalseTotal
if $v 0 0 0
48 return $self->{userData}
49 || {
50 ( $Lemonldap::NG::Handler::Main::tsv->{whatToTrace}
51 0 ▶ || '_whatToTrace' ) => $self->{user}, };
Condition0%0/4
$self->{'userData'} || {$Lemonldap::NG::Handler::Main::tsv->{'whatToTrace'} || '_whatToTrace', $self->{'user'}}
l!l
00
$Lemonldap::NG::Handler::Main::tsv->{'whatToTrace'} || '_whatToTrace'
l!l
00
MC/DC0%0/1
$self->{'userData'} || {$Lemonldap::NG::Handler::Main::tsv->{'whatToTrace'} || '_whatToTrace', $self->{'user'}}
$self->{'userData'}
MC/DC0%0/1
$Lemonldap::NG::Handler::Main::tsv->{'whatToTrace'} || '_whatToTrace'
$Lemonldap::NG::Handler::Main::tsv->{'whatToTrace'}
Truth table0%0/2
A
A= $self->{'userData'}
Aresult
11
00
Truth table0%0/2
A
A= $Lemonldap::NG::Handler::Main::tsv->{'whatToTrace'}
Aresult
11
00
52 }
53  
54 sub respHeaders {
55 0 ▶ my ( $self, $respHeaders ) = @_;
Subroutine respHeaders: not called CC=2 SCAR=17.9
Pod documented
56 0 ▶ $self->{respHeaders} = $respHeaders if ($respHeaders);
Branch: 1 branch
BranchTrueFalseTotal
if $respHeaders 0 0 0
57 0 return $self->{respHeaders};
58 }
59  
60 sub spliceHdrs {
61 0 ▶ my ($self) = @_;
Subroutine spliceHdrs: not called CC=1 SCAR=6.9
Pod documented
62 0 return splice @{ $self->{respHeaders} };
63 }
64  
65 0 ▶sub accept { $_[0]->env->{HTTP_ACCEPT} }
Subroutine accept: not called CC=1 SCAR=6.9
Pod documented
66 0 ▶sub encodings { $_[0]->env->{HTTP_ACCEPT_ENCODING} }
Subroutine encodings: not called CC=1 SCAR=6.9
Pod documented
67 0 ▶sub languages { $_[0]->env->{HTTP_ACCEPT_LANGUAGE} }
Subroutine languages: not called CC=1 SCAR=6.9
Pod documented
68 0 ▶sub authorization { $_[0]->env->{HTTP_AUTHORIZATION} }
Subroutine authorization: not called CC=1 SCAR=6.9
Pod undocumented
69 0 ▶sub hostname { $_[0]->env->{HTTP_HOST} }
Subroutine hostname: not called CC=1 SCAR=6.9
Pod documented
70 0 ▶sub origin { $_[0]->env->{HTTP_ORIGIN} }
Subroutine origin: not called CC=1 SCAR=6.9
Pod undocumented
71 0 ▶sub referer { $_[0]->env->{REFERER} }
Subroutine referer: not called CC=1 SCAR=6.9
Pod documented
72 0 ▶sub query_string { $_[0]->env->{QUERY_STRING} }
Subroutine query_string: not called CC=1 SCAR=6.9
Pod documented
73  
74 sub error {
75 0 ▶ my ( $self, $err ) = @_;
Subroutine error: not called CC=2 SCAR=17.9
Pod documented
76 0 ▶ $self->{error} = $err if ($err);
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 0 0
77 0 return $self->{error};
78 }
79  
80 8 *params = \&Plack::Request::param;
81  
82 sub set_param {
83 0 ▶ my ( $self, $k, $v ) = @_;
Subroutine set_param: not called CC=1 SCAR=6.9
Pod documented
84 0 $self->param;
85 $self->env->{'plack.request.merged'}->{$k} =
86 0 $self->env->{'plack.request.query'}->{$k} = $v;
87 }
88  
89 sub wantJSON {
90 0 ▶ return 1
Subroutine wantJSON: not called CC=3 SCAR=24.8
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0]->accept and $_[0]->accept =~ m[(?:application|text)/json] 0 0 0
Condition0%0/3
defined $_[0]->accept and $_[0]->accept =~ m[(?:application|text)/json]
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_[0]->accept and $_[0]->accept =~ m[(?:application|text)/json]
defined $_[0]->accept $_[0]->accept =~ m[(?:application|text)/json]
Truth table0%0/3
A and B
A= defined $_[0]->acceptB= $_[0]->accept =~ m[(?:application|text)/json]
ABresult
0X0
100
111
91 if ( defined $_[0]->accept
92 and $_[0]->accept =~ m#(?:application|text)/json# );
93 0 return 0;
94 }
95  
96 # JSON parser
97 sub jsonBodyToObj {
98 1 ▶ my $self = shift;
Subroutine jsonBodyToObj: called CC=5 SCAR=19.9
Pod documented
99 1 ▶ return $self->{json_body} if ( $self->{json_body} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"json_body"} 0 1 1
100 1 ▶ unless ( $self->content_type =~ /application\/json/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->content_type =~ m[application/json]) 0 1 1
101 0 $self->error('Data is not JSON');
102 0 return undef;
103 }
104 1 ▶ unless ( $self->body ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->body) 0 1 1
105 0 $self->error('No data');
106 0 return undef;
107 }
108 1 my $j = eval { from_json( $self->content, { allow_nonref => 1 } ) };
109 1 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 1 1
110 0 $self->error("$@$!");
111 0 return undef;
112 }
113 1 return $self->{json_body} = $j;
114 }
115  
116 8 1;
117 __END__
« blib/lib/Lemonldap/NG/Common/Conf/Backends/_DBI.pm ↑ Summary blib/lib/Lemonldap/NG/Common/PSGI/Cli/Lib.pm »