| 1 | #=============================================================================== | ||||||||||||||||||||||||||||
| 2 | # | ||||||||||||||||||||||||||||
| 3 | # DESCRIPTION: controller | ||||||||||||||||||||||||||||
| 4 | # | ||||||||||||||||||||||||||||
| 5 | # AUTHOR: Aliaksandr P. Zahatski, <zahatski@gmail.com> | ||||||||||||||||||||||||||||
| 6 | #=============================================================================== | ||||||||||||||||||||||||||||
| 7 | #$Id$ | ||||||||||||||||||||||||||||
| 8 | package WebDAO::CV; | ||||||||||||||||||||||||||||
| 9 | 5 | our $VERSION = '0.01'; | |||||||||||||||||||||||||||
| 10 | 5 | ▶ | use URI; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 5 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 5 | ▶ | use HTTP::Body; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 5 | ▶ | use WebDAO::Base; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 5 | ▶ | use base qw( WebDAO::Base ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 5 | __PACKAGE__->mk_attr(status=>200, _parsed_cookies=>undef); | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | sub new { | ||||||||||||||||||||||||||||
| 21 | 13 | ▶ | my $class = shift; | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=12.0
Pod
documented
| |||||||||||||||||||||||||||||
| 22 | 13 | ▶ | my $self = bless( ( $#_ == 0 ) ? shift : {@_}, ref($class) || $class ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table33%1/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||||||||||
| 23 | 13 | $self->{headers} = {}; | |||||||||||||||||||||||||||
| 24 | 13 | $self | |||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | =head2 url (-options1=>1) | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | from url: http://testwd.zag:82/Envs/partsh.sd?23=23 | ||||||||||||||||||||||||||||
| 30 | where options: | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | -path_info -> /Envs/partsh.sd | ||||||||||||||||||||||||||||
| 33 | -base -> http://example.com:82 | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | defaul http://testwd.zag:82/Envs/partsh.sd?23=23 | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | =cut | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | sub url { | ||||||||||||||||||||||||||||
| 40 | 20 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
url: called CC=9 SCAR=22.0
Pod
documented
| |||||||||||||||||||||||||||||
| 41 | 20 | my %args = @_; | |||||||||||||||||||||||||||
| 42 | 20 | my $env = $self->{env}; | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 20 | ▶ | if ( exists $env->{FCGI_ROLE} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | ( $env->{PATH_INFO}, $env->{QUERY_STRING} ) = | ||||||||||||||||||||||||||||
| 46 | 4 | $env->{REQUEST_URI} =~ /([^?]*)(?:\?(.*)$)?/s; | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | 20 | ▶ | my $path = $env->{PATH_INFO} || ''; # 'PATH_INFO' => '/Env' | ||||||||||||||||||||||||||
|
Condition100%2/2
$env->{'PATH_INFO'} || ''
MC/DC100%1/1
$env->{'PATH_INFO'} || ''
$env->{'PATH_INFO'}
Truth table100%2/2
A
A= $env->{'PATH_INFO'}
| |||||||||||||||||||||||||||||
| 49 | 20 | ▶ | my $host = $env->{HTTP_HOST} || 'example.org'; # 'HTTP_HOST' => '127.0.0.1:5000' | ||||||||||||||||||||||||||
|
Condition100%2/2
$env->{'HTTP_HOST'} || 'example.org'
MC/DC100%1/1
$env->{'HTTP_HOST'} || 'example.org'
$env->{'HTTP_HOST'}
Truth table100%2/2
A
A= $env->{'HTTP_HOST'}
| |||||||||||||||||||||||||||||
| 50 | 20 | ▶ | my $query = $env->{QUERY_STRING}|| ''; # 'QUERY_STRING' => '434=34&erer=2' | ||||||||||||||||||||||||||
|
Condition100%2/2
$env->{'QUERY_STRING'} || ''
MC/DC100%1/1
$env->{'QUERY_STRING'} || ''
$env->{'QUERY_STRING'}
Truth table100%2/2
A
A= $env->{'QUERY_STRING'}
| |||||||||||||||||||||||||||||
| 51 | 20 | ▶ | my $proto = $env->{'psgi.url_scheme'} || 'http'; | ||||||||||||||||||||||||||
|
Condition50%1/2
$env->{'psgi.url_scheme'} || 'http'
MC/DC0%0/1
$env->{'psgi.url_scheme'} || 'http'
$env->{'psgi.url_scheme'}
Truth table50%1/2
A
A= $env->{'psgi.url_scheme'}
| |||||||||||||||||||||||||||||
| 52 | 20 | my $full_path = "$proto://${host}${path}?$query"; | |||||||||||||||||||||||||||
| 53 | #clear / at end | ||||||||||||||||||||||||||||
| 54 | 20 | ▶ | $full_path =~ s!/$!! if $path =~ m!^/!; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | 20 | my $uri = URI->new($full_path); | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 20 | ▶ | if ( exists $args{-path_info} ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 58 | 5 | return $uri->path(); | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | elsif ( exists $args{-base} ) { | ||||||||||||||||||||||||||||
| 61 | 9 | return "$proto://$host"; | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | 6 | return URI->new($full_path)->canonical; | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | =head2 method | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | retrun HTTP method | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | =cut | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | sub method { | ||||||||||||||||||||||||||||
| 73 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
method: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||||||||||||||||||||
| 74 | 1 | ▶ | $self->{env}->{REQUEST_METHOD} || "GET"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | =head2 | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | return hashref | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | { | ||||||||||||||||||||||||||||
| 82 | 'application/xhtml+xml' => undef, | ||||||||||||||||||||||||||||
| 83 | 'application/xml' => undef, | ||||||||||||||||||||||||||||
| 84 | 'text/html' => undef | ||||||||||||||||||||||||||||
| 85 | }; | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | =cut | ||||||||||||||||||||||||||||
| 88 | sub accept { | ||||||||||||||||||||||||||||
| 89 | 5 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
accept: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 90 | 5 | ▶ | my $accept = $self->{env}->{HTTP_ACCEPT} || return {}; | ||||||||||||||||||||||||||
|
Condition100%2/2
$self->{'env'}{'HTTP_ACCEPT'} || (return {})
MC/DC100%1/1
$self->{'env'}{'HTTP_ACCEPT'} || (return {})
$self->{'env'}{'HTTP_ACCEPT'}
Truth table100%2/2
A
A= $self->{'env'}{'HTTP_ACCEPT'}
| |||||||||||||||||||||||||||||
| 91 | 1 | my ($types) = split( ';', $accept ); | |||||||||||||||||||||||||||
| 92 | 1 | my %res; | |||||||||||||||||||||||||||
| 93 | 1 | @res{ split( ',', $types ) } = (); | |||||||||||||||||||||||||||
| 94 | 1 | \%res; | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | =head2 param | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | return params | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | =cut | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | sub param { | ||||||||||||||||||||||||||||
| 104 | 9 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
param: called CC=10 SCAR=27.4
Pod
documented
| |||||||||||||||||||||||||||||
| 105 | 9 | my $params = $self->{parsed_params}; | |||||||||||||||||||||||||||
| 106 | 9 | ▶ | unless ($params) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 107 | #init by POST params | ||||||||||||||||||||||||||||
| 108 | 5 | $params = $self->_parse_body; | |||||||||||||||||||||||||||
| 109 | 5 | my @get_params = $self->url()->query_form; | |||||||||||||||||||||||||||
| 110 | 5 | ▶ | while (my ($k, $v) = splice(@get_params,0,2 )) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 111 | 1 | ▶ | unless ( exists $params->{ $k } ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 112 | 1 | $params->{ $k } = $v | |||||||||||||||||||||||||||
| 113 | } else { | ||||||||||||||||||||||||||||
| 114 | 0 | my $val = $params->{ $k }; | |||||||||||||||||||||||||||
| 115 | #if array ? | ||||||||||||||||||||||||||||
| 116 | 0 | ▶ | if ( ref $val ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 117 | 0 | push @$val, $v | |||||||||||||||||||||||||||
| 118 | } else { | ||||||||||||||||||||||||||||
| 119 | 0 | ▶ | $params->{ $k } = [$val, ref($v) ? @$v : $v] | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | 5 | $self->{parsed_params} = $params; | |||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||
| 125 | 9 | ▶ | return keys %$params unless @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 126 | 1 | ▶ | return undef unless exists $params->{$_[0]}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 127 | 1 | my $res = $params->{$_[0]}; | |||||||||||||||||||||||||||
| 128 | 1 | ▶ | if ( ref($res) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 129 | 0 | ▶ | return wantarray ? @$res : $res->[0] | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | 1 | return $res; | |||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | #parse body | ||||||||||||||||||||||||||||
| 135 | sub _parse_body { | ||||||||||||||||||||||||||||
| 136 | 5 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_parse_body: called CC=8 SCAR=37.4
| |||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | 5 | my $content_type = $self->{env}->{CONTENT_TYPE}; | |||||||||||||||||||||||||||
| 139 | 5 | my $content_length = $self->{env}->{CONTENT_LENGTH}; | |||||||||||||||||||||||||||
| 140 | 5 | ▶ | if (!$content_type && !$content_length) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$content_type or $content_length
MC/DC0%0/2
$content_type or $content_length
$content_type
$content_length
Truth table33%1/3
A or B
A= $content_typeB= $content_length
| |||||||||||||||||||||||||||||
| 141 | 5 | return {}; | |||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | 0 | my $body = HTTP::Body->new($content_type, $content_length); | |||||||||||||||||||||||||||
| 145 | 0 | $body->cleanup(1); | |||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | 0 | my $input = $self->{env}->{'psgi.input'}; | |||||||||||||||||||||||||||
| 148 | 0 | ▶ | if ( $input ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 149 | #reset IO | ||||||||||||||||||||||||||||
| 150 | 0 | $input->seek(0,0); | |||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||
| 152 | else { | ||||||||||||||||||||||||||||
| 153 | # for FCGI, Shell | ||||||||||||||||||||||||||||
| 154 | 0 | $input = \*STDIN | |||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||
| 156 | 0 | my $spin = 0; | |||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | 0 | ▶ | while ($content_length) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 159 | 0 | ▶ | $input->read(my $chunk, $content_length < 8192 ? $content_length : 8192); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 160 | 0 | my $read = length $chunk; | |||||||||||||||||||||||||||
| 161 | 0 | $content_length -= $read; | |||||||||||||||||||||||||||
| 162 | 0 | $body->add($chunk); | |||||||||||||||||||||||||||
| 163 | 0 | ▶ | if ($read == 0 && $spin++ > 2000) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$read == 0 and $spin++ > 2000
MC/DC0%0/2
$read == 0 and $spin++ > 2000
$read == 0
$spin++ > 2000
Truth table0%0/3
A and B
A= $read == 0B= $spin++ > 2000
| |||||||||||||||||||||||||||||
| 164 | 0 | Carp::croak "Bad Content-Length: maybe client disconnect? ($content_length bytes remaining)"; | |||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||
| 167 | 0 | $self->{'http.body'} = $body; | |||||||||||||||||||||||||||
| 168 | 0 | return $body->param | |||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | =head2 body | ||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | Return HTTP body file descriptor | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | my $body; | ||||||||||||||||||||||||||||
| 176 | { | ||||||||||||||||||||||||||||
| 177 | local $/; | ||||||||||||||||||||||||||||
| 178 | my $fd = $r->get_request->body; | ||||||||||||||||||||||||||||
| 179 | $body = <$fd>; | ||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | =cut | ||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | sub body { | ||||||||||||||||||||||||||||
| 185 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
body: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 186 | 0 | ▶ | unless ( exists $self->{'http.body'} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 187 | 0 | $self->_parse_body(); | |||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | 0 | ▶ | my $http_body = $self->{'http.body'} || return undef; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->{'http.body'} || (return undef)
MC/DC0%0/1
$self->{'http.body'} || (return undef)
$self->{'http.body'}
Truth table0%0/2
A
A= $self->{'http.body'}
| |||||||||||||||||||||||||||||
| 191 | 0 | return $http_body->body; | |||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | =head2 get-body | ||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | Return HTTP body text | ||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | my $body= $r->get_request->get_body; | ||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | =cut | ||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | sub get_body { | ||||||||||||||||||||||||||||
| 203 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
get_body: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 204 | 0 | my $body; | |||||||||||||||||||||||||||
| 205 | { | ||||||||||||||||||||||||||||
| 206 | 0 | local $/; | |||||||||||||||||||||||||||
| 207 | 0 | ▶ | if ( my $fd = $self->body ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 208 | 0 | $body = <$fd> | |||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||
| 211 | 0 | return $body | |||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | =head2 set_header | ||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||
| 216 | $cv->set_header("Content-Type" => 'text/html; charset=utf-8') | ||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | =cut | ||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||
| 220 | sub set_header { | ||||||||||||||||||||||||||||
| 221 | 5 | ▶ | my ( $self, $name, $par ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
set_header: called CC=2 SCAR=8.4
Pod
documented
| |||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | #collect -cookies | ||||||||||||||||||||||||||||
| 224 | 5 | ▶ | if ( $name eq 'Set-Cookie' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 225 | 0 | push @{ $self->{headers}->{$name} }, $par; | |||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||
| 227 | else { | ||||||||||||||||||||||||||||
| 228 | 5 | $self->{headers}->{$name} = $par; | |||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||
| 232 | =head3 print_headers [ header1=>value, ...] | ||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||
| 234 | Method for output headers | ||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||
| 236 | =cut | ||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | sub print_headers { | ||||||||||||||||||||||||||||
| 239 | 4 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
print_headers: called CC=8 SCAR=21.3
Pod
documented
| |||||||||||||||||||||||||||||
| 240 | #save cookie | ||||||||||||||||||||||||||||
| 241 | 4 | my $cookie = delete $self->{headers}->{"Set-Cookie"}; | |||||||||||||||||||||||||||
| 242 | #merge in and exists headers | ||||||||||||||||||||||||||||
| 243 | 4 | my %headers = ( %{ $self->{headers} } , @_ ); | |||||||||||||||||||||||||||
| 244 | #merge cookies | ||||||||||||||||||||||||||||
| 245 | 4 | ▶ | if ( $cookie ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 246 | 0 | push @{ $headers{"Set-Cookie"} }, @$cookie; | |||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||
| 248 | 4 | my @cookies_headers = (); | |||||||||||||||||||||||||||
| 249 | #format cookies | ||||||||||||||||||||||||||||
| 250 | 4 | ▶ | if ( my $cookies = delete $headers{"Set-Cookie"} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 251 | 1 | foreach my $c ( @$cookies ) { | |||||||||||||||||||||||||||
| 252 | 2 | my $hvalue; | |||||||||||||||||||||||||||
| 253 | 2 | ▶ | if (ref($c) eq 'HASH') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 254 | 2 | ▶ | my $path = $c->{path} || '/'; | ||||||||||||||||||||||||||
|
Condition50%1/2
$c->{'path'} || '/'
MC/DC0%0/1
$c->{'path'} || '/'
$c->{'path'}
Truth table50%1/2
A
A= $c->{'path'}
| |||||||||||||||||||||||||||||
| 255 | # Set-Cookie: srote=ewe&1&1&2; path=$path | ||||||||||||||||||||||||||||
| 256 | 2 | $hvalue = "$c->{name}=$c->{value}; path=$path"; | |||||||||||||||||||||||||||
| 257 | 2 | ▶ | if (my $expires = $c->{expires}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 258 | 1 | my @MON = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec ); | |||||||||||||||||||||||||||
| 259 | 1 | my @WDAY = qw( Sun Mon Tue Wed Thu Fri Sat ); | |||||||||||||||||||||||||||
| 260 | 1 | my($sec, $min, $hour, $mday, $mon, $year, $wday) = gmtime($expires); | |||||||||||||||||||||||||||
| 261 | 1 | $year += 1900; | |||||||||||||||||||||||||||
| 262 | 1 | $expires = sprintf("%s, %02d-%s-%04d %02d:%02d:%02d GMT", | |||||||||||||||||||||||||||
| 263 | $WDAY[$wday], $mday, $MON[$mon], $year, $hour, $min, $sec); | ||||||||||||||||||||||||||||
| 264 | 1 | $hvalue .=" ;expires=$expires"; | |||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||
| 266 | 0 | } else { $hvalue = $c } | |||||||||||||||||||||||||||
| 267 | 2 | push @cookies_headers, "Set-Cookie", $hvalue; | |||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||
| 270 | 4 | my $status = $self->status; | |||||||||||||||||||||||||||
| 271 | 4 | ▶ | my $fd = $self->{writer}->([$status||"200", [%headers, @cookies_headers], undef]); | ||||||||||||||||||||||||||
|
Condition50%1/2
$status || '200'
MC/DC0%0/1
$status || '200'
$status
Truth table50%1/2
A
A= $status
| |||||||||||||||||||||||||||||
| 272 | 4 | $self->{fd} = $fd; | |||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||
| 275 | sub print { | ||||||||||||||||||||||||||||
| 276 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
print: called CC=4 SCAR=14.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 277 | 1 | ▶ | if (exists $self->{fd}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 278 | 1 | foreach my $line (@_) { | |||||||||||||||||||||||||||
| 279 | 1 | ▶ | utf8::encode( $line) if utf8::is_utf8($line); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 280 | 1 | $self->{fd}->write($line); | |||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||
| 282 | } else { | ||||||||||||||||||||||||||||
| 283 | 0 | print @_; | |||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||
| 287 | =head2 get_cookie | ||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||
| 289 | return hashref to {key=>value} | ||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||
| 291 | =cut | ||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||
| 293 | sub get_cookie { | ||||||||||||||||||||||||||||
| 294 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
get_cookie: called CC=3 SCAR=11.3
Pod
documented
| |||||||||||||||||||||||||||||
| 295 | 1 | ▶ | my $str = $self->{env}->{HTTP_COOKIE} || return {}; | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->{'env'}{'HTTP_COOKIE'} || (return {})
MC/DC0%0/1
$self->{'env'}{'HTTP_COOKIE'} || (return {})
$self->{'env'}{'HTTP_COOKIE'}
Truth table50%1/2
A
A= $self->{'env'}{'HTTP_COOKIE'}
| |||||||||||||||||||||||||||||
| 296 | 1 | ▶ | if ($self->_parsed_cookies) { return $self->_parsed_cookies }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 297 | 1 | my %res; | |||||||||||||||||||||||||||
| 298 | %res = | ||||||||||||||||||||||||||||
| 299 | 1 | map { URI::Escape::uri_unescape($_) } map { split '=',$_,2 } split(/\s*[;]\s*/, | |||||||||||||||||||||||||||
| 300 | $str); | ||||||||||||||||||||||||||||
| 301 | 1 | $self->_parsed_cookies(\%res); | |||||||||||||||||||||||||||
| 302 | 1 | \%res; | |||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||
| 306 | 5 | 1; | |||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||