| 1 | package YATT::Lite::Connection; sub PROP () {__PACKAGE__} | ||||||||||||||||||||||||||||
| 2 | 73 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 73 | ▶ | use warnings qw(FATAL all NONFATAL misc); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 73 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 73 | ▶ | use Hash::Util qw/lock_keys/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | # XXX: MFields may be ok. | ||||||||||||||||||||||||||||
| 9 | use YATT::Lite::MFields | ||||||||||||||||||||||||||||
| 10 | 73 | ▶ | (# Incoming request. Should be filled by Dispatcher(Factory) | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 73 | [env => getter => [env => 'glob']] | |||||||||||||||||||||||||||
| 12 | , qw/_cookies_in/ | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | # To debug liveness/leakage. | ||||||||||||||||||||||||||||
| 15 | , qw/debug/ | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | # Outgoing response. Should be written by YATT and *.yatt | ||||||||||||||||||||||||||||
| 18 | , qw/parent_fh buffer | ||||||||||||||||||||||||||||
| 19 | _headers _header_was_sent | ||||||||||||||||||||||||||||
| 20 | status content_type charset encoding | ||||||||||||||||||||||||||||
| 21 | _cookies_out/ | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | # To suppress HTTP header, set this. | ||||||||||||||||||||||||||||
| 24 | , 'noheader' | ||||||||||||||||||||||||||||
| 25 | # To suppress flush_header on DESTROY, set this. | ||||||||||||||||||||||||||||
| 26 | , 'no_auto_flush_headers' | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | # To distinguish error state. | ||||||||||||||||||||||||||||
| 29 | , qw/_is_error _raised _oldbuf _diag_list _error_list/ | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | # Session store | ||||||||||||||||||||||||||||
| 32 | , qw/_session _stash _debug_stash/ | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | # For logging, compatible to psgix.logger (I hope. Not yet used.) | ||||||||||||||||||||||||||||
| 35 | , qw/logger/ | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | # For poorman's logging logdump() series. | ||||||||||||||||||||||||||||
| 38 | , qw/logfh/ | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | # Invocation context | ||||||||||||||||||||||||||||
| 41 | , qw/system yatt backend dbh/ | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | # Raw path_info. should match with env->{PATH_INFO} | ||||||||||||||||||||||||||||
| 44 | , qw/path_info/ | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | # Location quad, is_index flag and request_file (GH-251). | ||||||||||||||||||||||||||||
| 47 | # request_file keeps the file name part as it appeared in the | ||||||||||||||||||||||||||||
| 48 | # request. (file - request_file = extension supplemented by lookup) | ||||||||||||||||||||||||||||
| 49 | , qw/dir location file subpath | ||||||||||||||||||||||||||||
| 50 | is_index | ||||||||||||||||||||||||||||
| 51 | request_file/ | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | # Not used.. | ||||||||||||||||||||||||||||
| 54 | , qw/root/ | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | # User's choice of message language. | ||||||||||||||||||||||||||||
| 57 | , qw/lang/ | ||||||||||||||||||||||||||||
| 58 | 73 | ); | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 73 | ▶ | use YATT::Lite::Util qw( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 61 | globref lexpand fields_hash incr_opt terse_dump | ||||||||||||||||||||||||||||
| 62 | raise_response | ||||||||||||||||||||||||||||
| 63 | 73 | ); | |||||||||||||||||||||||||||
| 64 | 73 | ▶ | use YATT::Lite::PSGIEnv; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 19976 | ▶ | sub prop { *{shift()}{HASH} } | ||||||||||||||||||||||||||
|
Subroutine
prop: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 0 | ▶ | sub YATT { | ||||||||||||||||||||||||||
|
Subroutine
YATT: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 69 | 0 | my PROP $prop = prop(my $glob = shift); | |||||||||||||||||||||||||||
| 70 | 0 | $prop->{yatt}; | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | # $SYS is derivable from $CON: $SYS == $CON->system ($YATT == $CON->YATT). | ||||||||||||||||||||||||||||
| 74 | 1 | ▶ | sub system { | ||||||||||||||||||||||||||
|
Subroutine
system: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 75 | 1 | my PROP $prop = prop(my $glob = shift); | |||||||||||||||||||||||||||
| 76 | 1 | $prop->{system}; | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | # # XXX: Experimental. This can slowdown 20%! the code like: print $CON (text); | ||||||||||||||||||||||||||||
| 80 | # use overload qw/%{} as_hash | ||||||||||||||||||||||||||||
| 81 | # bool as_bool/; | ||||||||||||||||||||||||||||
| 82 | # sub as_hash { *{shift()}{HASH} } | ||||||||||||||||||||||||||||
| 83 | # sub as_bool { defined $_[0] } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | #======================================== | ||||||||||||||||||||||||||||
| 86 | # Constructors | ||||||||||||||||||||||||||||
| 87 | #======================================== | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 703 | ▶ | sub create { | ||||||||||||||||||||||||||
|
Subroutine
create: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 90 | 703 | my ($class, $self) = splice @_, 0, 2; | |||||||||||||||||||||||||||
| 91 | 703 | require IO::Handle; | |||||||||||||||||||||||||||
| 92 | 703 | my ($prop, @task) = $class->build_prop(@_); | |||||||||||||||||||||||||||
| 93 | 703 | $class->build_fh_for($prop, $self); | |||||||||||||||||||||||||||
| 94 | 703 | $_->[0]->($self, $_->[1]) for @task; | |||||||||||||||||||||||||||
| 95 | 703 | $self->after_create; | |||||||||||||||||||||||||||
| 96 | 703 | $self; | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 703 | ▶ | sub after_create {} | ||||||||||||||||||||||||||
|
Subroutine
after_create: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 703 | ▶ | sub build_prop { | ||||||||||||||||||||||||||
|
Subroutine
build_prop: called CC=6 SCAR=18.6
Pod
undocumented
| |||||||||||||||||||||||||||||
| 102 | 703 | my $class = shift; | |||||||||||||||||||||||||||
| 103 | 703 | my $fields = fields_hash($class); | |||||||||||||||||||||||||||
| 104 | 703 | my PROP $prop = lock_keys(my %prop, keys %$fields); | |||||||||||||||||||||||||||
| 105 | 703 | my @task; | |||||||||||||||||||||||||||
| 106 | 703 | ▶ | while (my ($name, $value) = splice @_, 0, 2) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 107 | 10889 | ▶ | if ($name =~ /^_/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 108 | 0 | croak "Private field is prohibited: $name"; | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | 10889 | ▶ | if (my $sub = $class->can("configure_$name")) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 111 | 969 | push @task, [$sub, $value]; | |||||||||||||||||||||||||||
| 112 | } elsif (not exists $fields->{$name}) { | ||||||||||||||||||||||||||||
| 113 | 0 | confess "No such config item '$name' in class $class"; | |||||||||||||||||||||||||||
| 114 | } else { | ||||||||||||||||||||||||||||
| 115 | 9920 | $prop->{$name} = $value; | |||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | 703 | ▶ | wantarray ? ($prop, @task) : $prop; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 703 | ▶ | sub build_fh_for { | ||||||||||||||||||||||||||
|
Subroutine
build_fh_for: called CC=7 SCAR=20.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 122 | 703 | (my $class, my PROP $prop) = splice @_, 0, 2; | |||||||||||||||||||||||||||
| 123 | 703 | ▶ | unless (defined $_[0]) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 124 | 703 | ▶ | my $enc = $$prop{encoding} ? ":encoding($$prop{encoding})" : ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 125 | 703 | ▶ | $prop->{buffer} //= (\ my $str); | ||||||||||||||||||||||||||
|
Condition100%2/2
$prop->{"buffer"} //= \my $str
MC/DC100%1/1
$prop->{"buffer"} //= \my $str
$prop->{"buffer"}
Truth table100%2/2
A
A= $prop->{"buffer"}
| |||||||||||||||||||||||||||||
| 126 | 703 | ▶ | ${$prop->{buffer}} //= ""; | ||||||||||||||||||||||||||
|
Condition100%2/2
${$$prop{"buffer"};} //= ""
MC/DC100%1/1
${$$prop{"buffer"};} //= ""
${$$prop{"buffer"};}
Truth table100%2/2
A
A= ${$$prop{"buffer"};}
| |||||||||||||||||||||||||||||
| 127 | 703 | ▶ | open $_[0], ">$enc", $prop->{buffer} or die $!; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 128 | 0 | } elsif ($$prop{encoding}) { | |||||||||||||||||||||||||||
| 129 | 0 | binmode $_[0], ":encoding($$prop{encoding})"; | |||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | 703 | bless $_[0], $class; | |||||||||||||||||||||||||||
| 132 | 703 | *{$_[0]} = $prop; | |||||||||||||||||||||||||||
| 133 | 703 | $_[0]; | |||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | 1313 | ▶ | sub configure_encoding { | ||||||||||||||||||||||||||
|
Subroutine
configure_encoding: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 137 | 1313 | my PROP $prop = prop(my $glob = shift); | |||||||||||||||||||||||||||
| 138 | 1313 | my $enc = shift; | |||||||||||||||||||||||||||
| 139 | 1313 | $prop->{encoding} = $enc; | |||||||||||||||||||||||||||
| 140 | 1313 | binmode $glob, ":encoding($enc)"; | |||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | 0 | ▶ | sub get_encoding_layer { | ||||||||||||||||||||||||||
|
Subroutine
get_encoding_layer: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 144 | 0 | my PROP $prop = prop(my $glob = shift); | |||||||||||||||||||||||||||
| 145 | 0 | ▶ | $$prop{encoding} ? ":encoding($$prop{encoding})" : ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | #======================================== | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | 650 | ▶ | sub cget { | ||||||||||||||||||||||||||
|
Subroutine
cget: called CC=6 SCAR=19.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 151 | 650 | ▶ | confess "Not enough arguments" if @_ < 2; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 152 | 650 | ▶ | confess "Too many arguments" if @_ > 3; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 153 | 650 | my PROP $prop = prop(my $glob = shift); | |||||||||||||||||||||||||||
| 154 | 650 | my ($name, $default) = @_; | |||||||||||||||||||||||||||
| 155 | 650 | ▶ | if ($name =~ /^_/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 156 | 0 | croak "Private field is prohibited: $name"; | |||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||
| 158 | 650 | my $fields = fields_hash($glob); | |||||||||||||||||||||||||||
| 159 | 650 | ▶ | if (not exists $fields->{$name}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 160 | 0 | confess "No such config item '$name' in class " . ref $glob; | |||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||
| 162 | 650 | ▶ | $prop->{$name} // $default; | ||||||||||||||||||||||||||
|
Condition66%2/3
$prop->{$name} // $default
MC/DC50%1/2
$prop->{$name} // $default
$prop->{$name}
$default
Truth table66%2/3
A // B
A= $prop->{$name}B= $default
| |||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | 1664 | ▶ | sub configure { | ||||||||||||||||||||||||||
|
Subroutine
configure: called CC=8 SCAR=22.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 166 | 1664 | my PROP $prop = prop(my $glob = shift); | |||||||||||||||||||||||||||
| 167 | 1664 | my $fields = fields_hash($glob); | |||||||||||||||||||||||||||
| 168 | 1664 | my (@task); | |||||||||||||||||||||||||||
| 169 | 1664 | ▶ | while (my ($name, $value) = splice @_, 0, 2) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 170 | 1664 | ▶ | unless (defined $name) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 171 | 0 | croak "Undefined name given for @{[ref($glob)]}->configure(name=>value)!"; | |||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||
| 173 | 1664 | $name =~ s/^-//; | |||||||||||||||||||||||||||
| 174 | 1664 | ▶ | if ($name =~ /^_/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 175 | 0 | croak "Private field is prohibited: $name"; | |||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||
| 177 | 1664 | ▶ | if (my $sub = $glob->can("configure_$name")) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 178 | 975 | push @task, [$sub, $value]; | |||||||||||||||||||||||||||
| 179 | } elsif (not exists $fields->{$name}) { | ||||||||||||||||||||||||||||
| 180 | 0 | confess "No such config item '$name' in class " . ref $glob; | |||||||||||||||||||||||||||
| 181 | } else { | ||||||||||||||||||||||||||||
| 182 | 689 | $prop->{$name} = $value; | |||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||
| 185 | 1664 | ▶ | if (wantarray) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 186 | # To delay configure_zzz. | ||||||||||||||||||||||||||||
| 187 | 0 | @task; | |||||||||||||||||||||||||||
| 188 | } else { | ||||||||||||||||||||||||||||
| 189 | 1664 | $$_[0]->($glob, $$_[1]) for @task; | |||||||||||||||||||||||||||
| 190 | 1647 | $glob; | |||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | # For debugging aid. | ||||||||||||||||||||||||||||
| 195 | 1 | ▶ | sub cf_pairs { | ||||||||||||||||||||||||||
|
Subroutine
cf_pairs: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 196 | 1 | my PROP $prop = prop(my $glob = shift); | |||||||||||||||||||||||||||
| 197 | 1 | my $fields = fields_hash($glob); | |||||||||||||||||||||||||||
| 198 | map { | ||||||||||||||||||||||||||||
| 199 | 24 | [$_ => $prop->{$_}] | |||||||||||||||||||||||||||
| 200 | 1 | ▶ | } grep {!/^_/ && $_ ne 'buffer'} keys %$fields; | ||||||||||||||||||||||||||
|
Condition100%3/3
!/^_/ && $_ ne 'buffer'
MC/DC100%2/2
!/^_/ && $_ ne 'buffer'
!/^_/
$_ ne 'buffer'
Truth table100%3/3
not(A) && B
A= !/^_/B= $_ ne 'buffer'
| |||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||
| 203 | #======================================== | ||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | 478 | ▶ | sub is_error { | ||||||||||||||||||||||||||
|
Subroutine
is_error: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 206 | 478 | my PROP $prop = prop(my $glob = shift); | |||||||||||||||||||||||||||
| 207 | 478 | $prop->{_is_error}; | |||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | 194 | ▶ | sub as_error { | ||||||||||||||||||||||||||
|
Subroutine
as_error: called CC=4 SCAR=14.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 211 | 194 | my PROP $prop = prop(my $glob = shift); | |||||||||||||||||||||||||||
| 212 | 194 | $prop->{_is_error}++; | |||||||||||||||||||||||||||
| 213 | 194 | ▶ | if (my $buf = $prop->{buffer}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 214 | 194 | ▶ | push @{$prop->{_oldbuf}}, $$buf if $$buf ne ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 215 | 194 | $glob->rewind; | |||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||
| 217 | 194 | ▶ | $glob->configure(@_) if @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 218 | 194 | $glob; | |||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||
| 221 | 58 | ▶ | sub error_with_status { | ||||||||||||||||||||||||||
|
Subroutine
error_with_status: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 222 | 58 | my ($glob, $code) = splice @_, 0, 2; | |||||||||||||||||||||||||||
| 223 | 58 | $glob->as_error->configure(status => $code) | |||||||||||||||||||||||||||
| 224 | ->raise(error => incr_opt(depth => \@_), @_); | ||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | 19 | ▶ | sub error { | ||||||||||||||||||||||||||
|
Subroutine
error: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 228 | # XXX: as_error? | ||||||||||||||||||||||||||||
| 229 | 19 | shift->raise(error => incr_opt(depth => \@_), @_); | |||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||
| 232 | 79 | ▶ | sub raise { | ||||||||||||||||||||||||||
|
Subroutine
raise: called CC=5 SCAR=16.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 233 | 79 | my PROP $prop = prop(my $glob = shift); | |||||||||||||||||||||||||||
| 234 | 79 | my ($type, @err) = @_; # To keep args visible in backtrace. | |||||||||||||||||||||||||||
| 235 | 79 | $prop->{_raised} = $type; | |||||||||||||||||||||||||||
| 236 | 79 | ▶ | if (my $yatt = $prop->{yatt}) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 237 | 75 | $yatt->raise($type, incr_opt(depth => \@err), @err); | |||||||||||||||||||||||||||
| 238 | } elsif (my $system = $prop->{system}) { | ||||||||||||||||||||||||||||
| 239 | 0 | $system->raise($type, incr_opt(depth => \@err), @err); | |||||||||||||||||||||||||||
| 240 | } else { | ||||||||||||||||||||||||||||
| 241 | 4 | ▶ | shift @err if @err and ref $err[0] eq 'HASH'; # drop opts. | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@err and ref $err[0] eq "HASH"
MC/DC50%1/2
@err and ref $err[0] eq "HASH"
@err
ref $err[0] eq "HASH"
Truth table66%2/3
A and B
A= @errB= ref $err[0] eq "HASH"
| |||||||||||||||||||||||||||||
| 242 | 4 | my $fmt = shift @err; | |||||||||||||||||||||||||||
| 243 | 4 | croak sprintf($fmt, @err); | |||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||
| 247 | 0 | ▶ | sub error_fh { | ||||||||||||||||||||||||||
|
Subroutine
error_fh: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 248 | 0 | my PROP $prop = prop(my $glob = shift); | |||||||||||||||||||||||||||
| 249 | 0 | ▶ | if (my Env $env = $prop->{env}) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 250 | 0 | $env->{'psgi.errors'} | |||||||||||||||||||||||||||
| 251 | } elsif (fileno(STDERR)) { | ||||||||||||||||||||||||||||
| 252 | 0 | \*STDERR; | |||||||||||||||||||||||||||
| 253 | } else { | ||||||||||||||||||||||||||||
| 254 | 0 | undef; | |||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||
| 258 | # Simple level-less but tagged and serialized logging. | ||||||||||||||||||||||||||||
| 259 | 4 | ▶ | sub logdump { | ||||||||||||||||||||||||||
|
Subroutine
logdump: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 260 | 4 | my $self = shift; | |||||||||||||||||||||||||||
| 261 | 4 | $self->logemit($_[0], terse_dump(@_[1..$#_])); | |||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||
| 264 | 0 | ▶ | sub logbacktrace { | ||||||||||||||||||||||||||
|
Subroutine
logbacktrace: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 265 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 266 | 0 | $self->logemit($_[0], terse_dump(@_[1..$#_]), Carp::longmess()); | |||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||
| 269 | 4 | ▶ | sub logemit { | ||||||||||||||||||||||||||
|
Subroutine
logemit: called CC=9 SCAR=23.6
Pod
undocumented
| |||||||||||||||||||||||||||||
| 270 | 4 | my PROP $prop = prop(my $glob = shift); | |||||||||||||||||||||||||||
| 271 | 4 | ▶ | my $fh = $prop->{logfh} || $glob->error_fh; | ||||||||||||||||||||||||||
|
Condition33%1/3
$prop->{'logfh'} || $glob->error_fh
MC/DC0%0/2
$prop->{'logfh'} || $glob->error_fh
$prop->{'logfh'}
$glob->error_fh
Truth table33%1/3
A || B
A= $prop->{'logfh'}B= $glob->error_fh
| |||||||||||||||||||||||||||||
| 272 | 4 | my $logger = $prop->{logger}; | |||||||||||||||||||||||||||
| 273 | 4 | ▶ | return unless $fh || $logger; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$fh or $logger
MC/DC0%0/2
$fh or $logger
$fh
$logger
Truth table33%1/3
A or B
A= $fhB= $logger
| |||||||||||||||||||||||||||||
| 274 | 4 | my $tag = do { | |||||||||||||||||||||||||||
| 275 | 4 | ▶ | unless (defined $_[0]) { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 276 | 1 | shift; | |||||||||||||||||||||||||||
| 277 | 1 | 'undef' | |||||||||||||||||||||||||||
| 278 | } elsif (ref $_[0]) { | ||||||||||||||||||||||||||||
| 279 | 1 | unshift @_, terse_dump(shift @_); | |||||||||||||||||||||||||||
| 280 | 1 | 'debug'; | |||||||||||||||||||||||||||
| 281 | } elsif ($_[0] =~ /^[\w\.\-]+$/) { | ||||||||||||||||||||||||||||
| 282 | 1 | shift; | |||||||||||||||||||||||||||
| 283 | } else { | ||||||||||||||||||||||||||||
| 284 | 1 | 'debug'; | |||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||
| 286 | }; | ||||||||||||||||||||||||||||
| 287 | 4 | my $msg = join(" ", map {(my $cp = $_) =~ s/\n/\n /g; $cp} @_); | |||||||||||||||||||||||||||
| 288 | 4 | ▶ | if ($fh) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 289 | 4 | print $fh uc($tag).": [", $glob->iso8601_datetime(), " #$$] $msg\n"; | |||||||||||||||||||||||||||
| 290 | } else { | ||||||||||||||||||||||||||||
| 291 | 0 | my ($level, $type) = $tag =~ /^(\w+)(?:\.([\w\-\.]+))?$/; | |||||||||||||||||||||||||||
| 292 | 0 | ▶ | $logger->({level => $level || 'debug', message => $msg}); | ||||||||||||||||||||||||||
|
Condition0%0/2
$level || 'debug'
MC/DC0%0/1
$level || 'debug'
$level
Truth table0%0/2
A
A= $level
| |||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||
| 296 | # XXX: precise? | ||||||||||||||||||||||||||||
| 297 | 4 | ▶ | sub iso8601_datetime { | ||||||||||||||||||||||||||
|
Subroutine
iso8601_datetime: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 298 | 4 | my ($glob, $time) = @_; | |||||||||||||||||||||||||||
| 299 | 4 | ▶ | my ($S, $M, $H, $d, $m, $y) = localtime($time // time); | ||||||||||||||||||||||||||
|
Condition50%1/2
$time // time
MC/DC0%0/1
$time // time
$time
Truth table50%1/2
A
A= $time
| |||||||||||||||||||||||||||||
| 300 | 4 | $y += 1900; $m++; | |||||||||||||||||||||||||||
| 301 | 4 | sprintf '%04d-%02d-%02dT%02d:%02d:%02d', ($y, $m, $d, $H, $M, $S); | |||||||||||||||||||||||||||
| 302 | } | ||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||
| 304 | # Alternative, for more rich logging. | ||||||||||||||||||||||||||||
| 305 | 0 | ▶ | sub logger { | ||||||||||||||||||||||||||
|
Subroutine
logger: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 306 | 0 | my PROP $prop = prop(my $glob = shift); | |||||||||||||||||||||||||||
| 307 | 0 | $prop->{logger}; | |||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||
| 310 | #======================================== | ||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||
| 312 | 703 | ▶ | DESTROY { | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=8 SCAR=24.7
| |||||||||||||||||||||||||||||
| 313 | # Note: localizing $@ in DESTROY is not so good idea in general. | ||||||||||||||||||||||||||||
| 314 | # But I do this here because I found some module stamps $@ in mkheader. | ||||||||||||||||||||||||||||
| 315 | # Anyway, in usual case, $con lives along with entire request processing, | ||||||||||||||||||||||||||||
| 316 | # so this may not be a problem. | ||||||||||||||||||||||||||||
| 317 | 703 | local $@; | |||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||
| 319 | 703 | my PROP $prop = prop(my $glob = shift); | |||||||||||||||||||||||||||
| 320 | $glob->flush_headers | ||||||||||||||||||||||||||||
| 321 | 703 | ▶ | unless $prop->{no_auto_flush_headers}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 322 | 703 | ▶ | if (my $backend = delete $prop->{backend}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 323 | 1 | ▶ | if ($prop->{debug} and my $errfh = $glob->error_fh) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$prop->{"debug"} and my $errfh = $glob->error_fh
MC/DC0%0/2
$prop->{"debug"} and my $errfh = $glob->error_fh
$prop->{"debug"}
my $errfh = $glob->error_fh
Truth table33%1/3
A and B
A= $prop->{"debug"}B= my $errfh = $glob->error_fh
| |||||||||||||||||||||||||||||
| 324 | 0 | print $errfh "DEBUG: Connection->backend is detached($backend)\n"; | |||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||
| 326 | # DBSchema->DESTROY should be called automatically. <- Have tests for this! | ||||||||||||||||||||||||||||
| 327 | #$backend->disconnect("Explicitly from Connection->DESTROY"); | ||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||
| 329 | 703 | ▶ | if ($prop->{debug} and my $errfh = $glob->error_fh) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$prop->{"debug"} and my $errfh = $glob->error_fh
MC/DC0%0/2
$prop->{"debug"} and my $errfh = $glob->error_fh
$prop->{"debug"}
my $errfh = $glob->error_fh
Truth table33%1/3
A and B
A= $prop->{"debug"}B= my $errfh = $glob->error_fh
| |||||||||||||||||||||||||||||
| 330 | 0 | print $errfh "DEBUG: Connection->DESTROY (glob=$glob, prop=$prop)\n"; | |||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||
| 332 | 703 | delete $prop->{$_} for keys %$prop; | |||||||||||||||||||||||||||
| 333 | #undef *$glob; | ||||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||
| 336 | 16 | ▶ | sub header_was_sent { | ||||||||||||||||||||||||||
|
Subroutine
header_was_sent: called CC=3 SCAR=12.7
Pod
undocumented
| |||||||||||||||||||||||||||||
| 337 | 16 | my PROP $prop = (my $glob = shift)->prop; | |||||||||||||||||||||||||||
| 338 | 16 | $prop->{_header_was_sent} = 1; | |||||||||||||||||||||||||||
| 339 | 16 | my $parent = $prop->{parent_fh}; | |||||||||||||||||||||||||||
| 340 | 16 | ▶ | if ($parent and my $sub = $parent->can('header_was_sent')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$parent and my $sub = $parent->can("header_was_sent")
MC/DC0%0/2
$parent and my $sub = $parent->can("header_was_sent")
$parent
my $sub = $parent->can("header_was_sent")
Truth table33%1/3
A and B
A= $parentB= my $sub = $parent->can("header_was_sent")
| |||||||||||||||||||||||||||||
| 341 | 0 | $sub->($parent); | |||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||
| 343 | } | ||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||
| 345 | 1807 | ▶ | sub flush_headers { | ||||||||||||||||||||||||||
|
Subroutine
flush_headers: called CC=6 SCAR=18.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 346 | 1807 | my PROP $prop = (my $glob = shift)->prop; | |||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||
| 348 | 1807 | ▶ | return if $prop->{_header_was_sent}++; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||
| 350 | 673 | my $was_error = $prop->{_is_error}; | |||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||
| 352 | 673 | $glob->finalize_headers; | |||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||
| 354 | 673 | ▶ | if (not $prop->{noheader}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 355 | 31 | ▶ | my $fh = $prop->{parent_fh} // $glob; | ||||||||||||||||||||||||||
|
Condition66%2/3
$prop->{"parent_fh"} // $glob
MC/DC0%0/2
$prop->{"parent_fh"} // $glob
$prop->{"parent_fh"}
$glob
Truth table66%2/3
A // B
A= $prop->{"parent_fh"}B= $glob
| |||||||||||||||||||||||||||||
| 356 | 31 | my $header = $glob->mkheader; | |||||||||||||||||||||||||||
| 357 | 31 | ▶ | if (not $was_error and my ($err) = $glob->error_list) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $was_error and my($err) = $glob->error_list
MC/DC0%0/2
not $was_error and my($err) = $glob->error_list
not $was_error
my($err) = $glob->error_list
Truth table33%1/3
not(A) and B
A= not $was_errorB= my($err) = $glob->error_list
| |||||||||||||||||||||||||||||
| 358 | 0 | die "\n\nError during first call of flush_headers(): $err\n"; | |||||||||||||||||||||||||||
| 359 | } else { | ||||||||||||||||||||||||||||
| 360 | 31 | print $fh $header; | |||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||
| 363 | 673 | $glob->flush; | |||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||
| 366 | 703 | ▶ | sub finalize_headers { | ||||||||||||||||||||||||||
|
Subroutine
finalize_headers: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 367 | 703 | my PROP $prop = (my $glob = shift)->prop; | |||||||||||||||||||||||||||
| 368 | 703 | ▶ | $prop->{yatt}->finalize_connection($glob) if $prop->{yatt}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 369 | 703 | ▶ | $prop->{system}->finalize_connection($glob) if $prop->{system}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 370 | 703 | ▶ | $glob->finalize_cookies if $prop->{_cookies_out}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 371 | } | ||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||
| 373 | 676 | ▶ | sub flush { | ||||||||||||||||||||||||||
|
Subroutine
flush: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 374 | 676 | my PROP $prop = (my $glob = shift)->prop; | |||||||||||||||||||||||||||
| 375 | 676 | $glob->IO::Handle::flush(); | |||||||||||||||||||||||||||
| 376 | 676 | ▶ | if ($prop->{parent_fh}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 377 | 14 | print {$prop->{parent_fh}} ${$prop->{buffer}}; | |||||||||||||||||||||||||||
| 378 | 14 | ${$prop->{buffer}} = ''; | |||||||||||||||||||||||||||
| 379 | 14 | $prop->{parent_fh}->IO::Handle::flush(); | |||||||||||||||||||||||||||
| 380 | # XXX: flush 後は、 parent_fh の dup にするべき。 | ||||||||||||||||||||||||||||
| 381 | # XXX: でも、 multipart (server push) とか continue とかは? | ||||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||
| 385 | 194 | ▶ | sub rewind { | ||||||||||||||||||||||||||
|
Subroutine
rewind: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 386 | 194 | my PROP $prop = (my $glob = shift)->prop; | |||||||||||||||||||||||||||
| 387 | 194 | seek *$glob, 0, 0; | |||||||||||||||||||||||||||
| 388 | 194 | ${$prop->{buffer}} = ''; | |||||||||||||||||||||||||||
| 389 | 194 | $glob; | |||||||||||||||||||||||||||
| 390 | } | ||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||
| 392 | #======================================== | ||||||||||||||||||||||||||||
| 393 | # Cookie support, based on Cookie::Baker | ||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||
| 395 | 76 | ▶ | sub cookies_in { | ||||||||||||||||||||||||||
|
Subroutine
cookies_in: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 396 | 76 | my PROP $prop = (my $glob = shift)->prop; | |||||||||||||||||||||||||||
| 397 | 76 | my Env $env = $prop->{env}; | |||||||||||||||||||||||||||
| 398 | 76 | ▶ | $prop->{_cookies_in} ||= do { | ||||||||||||||||||||||||||
|
Condition66%2/3
$prop->{"_cookies_in"} ||= do {
if (defined $env->{"HTTP_COOKIE"}) {
YATT::Lite::Util::permissive_require("Cookie::Baker");
Cookie::Baker::crush_cookie($env->{"HTTP_COOKIE"});
}
else {
{};
}
}
MC/DC0%0/2
$prop->{"_cookies_in"} ||= do {
if (defined $env->{"HTTP_COOKIE"}) {
YATT::Lite::Util::permissive_require("Cookie::Baker");
Cookie::Baker::crush_cookie($env->{"HTTP_COOKIE"});
}
else {
{};
}
}
$prop->{"_cookies_in"}
do {
if (defined $env->{"HTTP_COOKIE"}) {
YATT::Lite::Util::permissive_require("Cookie::Baker");
Cookie::Baker::crush_cookie($env->{"HTTP_COOKIE"});
}
else {
{};
}
}
Truth table66%2/3
A ||= B
A= $prop->{"_cookies_in"}B= do {
if (defined $env->{"HTTP_COOKIE"}) {
YATT::Lite::Util::permissive_require("Cookie::Baker");
Cookie::Baker::crush_cookie($env->{"HTTP_COOKIE"});
}
else {
{};
}
}
| |||||||||||||||||||||||||||||
| 399 | 39 | ▶ | if (defined $env->{HTTP_COOKIE}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 400 | 27 | YATT::Lite::Util::permissive_require('Cookie::Baker'); | |||||||||||||||||||||||||||
| 401 | 27 | Cookie::Baker::crush_cookie($env->{HTTP_COOKIE}); | |||||||||||||||||||||||||||
| 402 | } else { | ||||||||||||||||||||||||||||
| 403 | 12 | +{}; | |||||||||||||||||||||||||||
| 404 | } | ||||||||||||||||||||||||||||
| 405 | }; | ||||||||||||||||||||||||||||
| 406 | } | ||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||
| 408 | 8 | ▶ | sub set_cookie { | ||||||||||||||||||||||||||
|
Subroutine
set_cookie: called CC=5 SCAR=26.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 409 | 8 | my PROP $prop = (my $glob = shift)->prop; | |||||||||||||||||||||||||||
| 410 | 8 | ▶ | if (@_ == 1 and ref $_[0]) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@_ == 1 and ref $_[0]
MC/DC0%0/2
@_ == 1 and ref $_[0]
@_ == 1
ref $_[0]
Truth table33%1/3
A and B
A= @_ == 1B= ref $_[0]
| |||||||||||||||||||||||||||||
| 411 | 0 | my $cookie = shift; | |||||||||||||||||||||||||||
| 412 | 0 | ▶ | if (ref $cookie eq 'HASH') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 413 | 0 | ▶ | defined (my $name = $cookie->{name}) or do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 414 | 0 | Carp::croak "set_cookie: name is undef!"; | |||||||||||||||||||||||||||
| 415 | }; | ||||||||||||||||||||||||||||
| 416 | 0 | $prop->{_cookies_out}{$name} = $cookie; | |||||||||||||||||||||||||||
| 417 | } else { | ||||||||||||||||||||||||||||
| 418 | 0 | my $name = $cookie->name; | |||||||||||||||||||||||||||
| 419 | 0 | $prop->{_cookies_out}{$name} = $cookie; | |||||||||||||||||||||||||||
| 420 | } | ||||||||||||||||||||||||||||
| 421 | } else { | ||||||||||||||||||||||||||||
| 422 | 8 | my $name = shift; | |||||||||||||||||||||||||||
| 423 | 8 | $prop->{_cookies_out}{$name} = $glob->new_cookie($name, @_); | |||||||||||||||||||||||||||
| 424 | } | ||||||||||||||||||||||||||||
| 425 | } | ||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||
| 427 | 8 | ▶ | sub new_cookie { | ||||||||||||||||||||||||||
|
Subroutine
new_cookie: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 428 | 8 | my $glob = shift; # not used. | |||||||||||||||||||||||||||
| 429 | 8 | my ($name, $value, @opts) = @_; | |||||||||||||||||||||||||||
| 430 | 8 | YATT::Lite::Util::permissive_require('Cookie::Baker'); | |||||||||||||||||||||||||||
| 431 | 8 | my $baked = {value => $value}; | |||||||||||||||||||||||||||
| 432 | 8 | ▶ | while (my ($k, $v) = splice @opts, 0, 2) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 433 | 28 | $k =~ s/^-//; # For backward compatibility with CGI::Cookie style options. | |||||||||||||||||||||||||||
| 434 | 28 | $baked->{$k} = $v; | |||||||||||||||||||||||||||
| 435 | } | ||||||||||||||||||||||||||||
| 436 | 8 | Cookie::Baker::bake_cookie($name, $baked); | |||||||||||||||||||||||||||
| 437 | } | ||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||
| 439 | 8 | ▶ | sub finalize_cookies { | ||||||||||||||||||||||||||
|
Subroutine
finalize_cookies: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 440 | 8 | my PROP $prop = (my $glob = shift)->prop; | |||||||||||||||||||||||||||
| 441 | 8 | ▶ | return unless $prop->{_cookies_out}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 442 | 8 | $prop->{_headers}{'Set-Cookie'} = [values %{$prop->{_cookies_out}}]; | |||||||||||||||||||||||||||
| 443 | } | ||||||||||||||||||||||||||||
| 444 | #======================================== | ||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||
| 446 | # XXX: Should be renamed to result, text, as_text, as_string or value; | ||||||||||||||||||||||||||||
| 447 | 477 | ▶ | sub buffer { | ||||||||||||||||||||||||||
|
Subroutine
buffer: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 448 | 477 | my PROP $prop = prop(my $glob = shift); | |||||||||||||||||||||||||||
| 449 | 477 | $glob->IO::Handle::flush(); | |||||||||||||||||||||||||||
| 450 | 477 | ${$prop->{buffer}} | |||||||||||||||||||||||||||
| 451 | } | ||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||
| 453 | 0 | ▶ | sub diag_list { | ||||||||||||||||||||||||||
|
Subroutine
diag_list: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 454 | 0 | my PROP $prop = prop(my $glob = shift); | |||||||||||||||||||||||||||
| 455 | my $list = $prop->{_diag_list} | ||||||||||||||||||||||||||||
| 456 | 0 | ▶ | or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 457 | 0 | ▶ | wantarray ? @$list : $list; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 458 | } | ||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||
| 460 | 120 | ▶ | sub add_diag { | ||||||||||||||||||||||||||
|
Subroutine
add_diag: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 461 | 120 | my PROP $prop = prop(my $glob = shift); | |||||||||||||||||||||||||||
| 462 | 120 | push @{$prop->{_diag_list}}, shift; | |||||||||||||||||||||||||||
| 463 | 120 | $glob; | |||||||||||||||||||||||||||
| 464 | } | ||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||
| 466 | 138 | ▶ | sub error_list { | ||||||||||||||||||||||||||
|
Subroutine
error_list: called CC=3 SCAR=11.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 467 | 138 | my PROP $prop = prop(my $glob = shift); | |||||||||||||||||||||||||||
| 468 | my $list = $prop->{_error_list} | ||||||||||||||||||||||||||||
| 469 | 138 | ▶ | or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 470 | 107 | ▶ | wantarray ? @$list : $list; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 471 | } | ||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||
| 473 | 120 | ▶ | sub add_error { | ||||||||||||||||||||||||||
|
Subroutine
add_error: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 474 | 120 | my PROP $prop = prop(my $glob = shift); | |||||||||||||||||||||||||||
| 475 | 120 | push @{$prop->{_error_list}}, my $err = shift; | |||||||||||||||||||||||||||
| 476 | 120 | $glob->add_diag($err->reason); | |||||||||||||||||||||||||||
| 477 | 120 | $glob; | |||||||||||||||||||||||||||
| 478 | } | ||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||
| 480 | 0 | ▶ | sub oldbuf { | ||||||||||||||||||||||||||
|
Subroutine
oldbuf: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 481 | 0 | my PROP $prop = prop(my $glob = shift); | |||||||||||||||||||||||||||
| 482 | my $oldbuf = $prop->{_oldbuf} | ||||||||||||||||||||||||||||
| 483 | 0 | ▶ | or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 484 | 0 | ▶ | wantarray ? @$oldbuf : $oldbuf; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 485 | } | ||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||
| 487 | 31 | ▶ | sub mkheader { | ||||||||||||||||||||||||||
|
Subroutine
mkheader: called CC=4 SCAR=14.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 488 | 31 | my PROP $prop = (my $glob = shift)->prop; | |||||||||||||||||||||||||||
| 489 | 31 | ▶ | my ($code) = shift // $prop->{status} // 200; | ||||||||||||||||||||||||||
|
Condition40%2/5
(shift() // $prop->{"status"}) // 200
shift() // $prop->{"status"}
MC/DC0%0/2
(shift() // $prop->{"status"}) // 200
shift()
$prop->{"status"}
Truth table33%1/3
A // B
A= shift()B= $prop->{"status"}
| |||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||
| 491 | # For GH-200 (to avoid "Can't locate Clone.pm" from HTTP::Headers) | ||||||||||||||||||||||||||||
| 492 | 31 | YATT::Lite::Util::permissive_require('HTTP::Headers'); | |||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||
| 494 | my $headers = HTTP::Headers->new("Content-type", $glob->_mk_content_type | ||||||||||||||||||||||||||||
| 495 | , map($_ ? %$_ : (), $prop->{_headers}) | ||||||||||||||||||||||||||||
| 496 | 31 | ▶ | , @_); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 497 | 31 | YATT::Lite::Util::mk_http_status($code) | |||||||||||||||||||||||||||
| 498 | . $headers->as_string . "\015\012"; | ||||||||||||||||||||||||||||
| 499 | } | ||||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||
| 501 | 31 | ▶ | sub _mk_content_type { | ||||||||||||||||||||||||||
|
Subroutine
_mk_content_type: called CC=5 SCAR=17.0
| |||||||||||||||||||||||||||||
| 502 | 31 | my PROP $prop = (my $glob = shift)->prop; | |||||||||||||||||||||||||||
| 503 | 31 | ▶ | my $ct = $prop->{content_type} || "text/html"; | ||||||||||||||||||||||||||
|
Condition50%1/2
$prop->{'content_type'} || 'text/html'
MC/DC0%0/1
$prop->{'content_type'} || 'text/html'
$prop->{'content_type'}
Truth table50%1/2
A
A= $prop->{'content_type'}
| |||||||||||||||||||||||||||||
| 504 | 31 | ▶ | if ($ct =~ m{^text/} && $ct !~ /;\s*charset/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$ct =~ m[^text/] and not $ct =~ /;\s*charset/
MC/DC0%0/2
$ct =~ m[^text/] and not $ct =~ /;\s*charset/
$ct =~ m[^text/]
not $ct =~ /;\s*charset/
Truth table33%1/3
A and not(B)
A= $ct =~ m[^text/]B= not $ct =~ /;\s*charset/
| |||||||||||||||||||||||||||||
| 505 | 31 | ▶ | my $cs = $prop->{charset} || "utf-8"; | ||||||||||||||||||||||||||
|
Condition100%2/2
$prop->{'charset'} || 'utf-8'
MC/DC100%1/1
$prop->{'charset'} || 'utf-8'
$prop->{'charset'}
Truth table100%2/2
A
A= $prop->{'charset'}
| |||||||||||||||||||||||||||||
| 506 | 31 | $ct .= qq|; charset=$cs|; | |||||||||||||||||||||||||||
| 507 | } | ||||||||||||||||||||||||||||
| 508 | 31 | $ct; | |||||||||||||||||||||||||||
| 509 | } | ||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||
| 511 | 5 | ▶ | sub set_header { | ||||||||||||||||||||||||||
|
Subroutine
set_header: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 512 | 5 | my PROP $prop = prop(my $glob = shift); | |||||||||||||||||||||||||||
| 513 | 5 | my ($key, $value) = @_; | |||||||||||||||||||||||||||
| 514 | 5 | $prop->{_headers}{$key} = $value; | |||||||||||||||||||||||||||
| 515 | 5 | $glob; | |||||||||||||||||||||||||||
| 516 | } | ||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||
| 518 | 0 | ▶ | sub set_header_list { | ||||||||||||||||||||||||||
|
Subroutine
set_header_list: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 519 | 0 | my PROP $prop = prop(my $glob = shift); | |||||||||||||||||||||||||||
| 520 | 0 | ▶ | while (my ($k, $v) = splice @_, 0, 2) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 521 | 0 | $prop->{_headers}{$k} = $v; | |||||||||||||||||||||||||||
| 522 | } | ||||||||||||||||||||||||||||
| 523 | 0 | $glob; | |||||||||||||||||||||||||||
| 524 | } | ||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||
| 526 | 0 | ▶ | sub append_header { | ||||||||||||||||||||||||||
|
Subroutine
append_header: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 527 | 0 | my PROP $prop = prop(my $glob = shift); | |||||||||||||||||||||||||||
| 528 | 0 | my ($key, @values) = @_; | |||||||||||||||||||||||||||
| 529 | 0 | push @{$prop->{_headers}{$key}}, @values; | |||||||||||||||||||||||||||
| 530 | } | ||||||||||||||||||||||||||||
| 531 | |||||||||||||||||||||||||||||
| 532 | # For PSGI only. | ||||||||||||||||||||||||||||
| 533 | 391 | ▶ | sub list_header { | ||||||||||||||||||||||||||
|
Subroutine
list_header: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 534 | 391 | my PROP $prop = prop(my $glob = shift); | |||||||||||||||||||||||||||
| 535 | my $headers = $prop->{_headers} | ||||||||||||||||||||||||||||
| 536 | 391 | ▶ | or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 537 | map { | ||||||||||||||||||||||||||||
| 538 | 11 | my $k = $_; | |||||||||||||||||||||||||||
| 539 | 13 | map {$k => $_} lexpand($headers->{$k}); | |||||||||||||||||||||||||||
| 540 | } keys %$headers; | ||||||||||||||||||||||||||||
| 541 | } | ||||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||
| 543 | 0 | ▶ | sub content_type { | ||||||||||||||||||||||||||
|
Subroutine
content_type: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 544 | 0 | my PROP $prop = prop(my $glob = shift); | |||||||||||||||||||||||||||
| 545 | $prop->{content_type} | ||||||||||||||||||||||||||||
| 546 | 0 | } | |||||||||||||||||||||||||||
| 547 | 0 | ▶ | sub set_content_type { | ||||||||||||||||||||||||||
|
Subroutine
set_content_type: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 548 | 0 | my PROP $prop = prop(my $glob = shift); | |||||||||||||||||||||||||||
| 549 | 0 | $prop->{content_type} = shift; | |||||||||||||||||||||||||||
| 550 | 0 | $glob; | |||||||||||||||||||||||||||
| 551 | } | ||||||||||||||||||||||||||||
| 552 | |||||||||||||||||||||||||||||
| 553 | 0 | ▶ | sub charset { | ||||||||||||||||||||||||||
|
Subroutine
charset: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 554 | 0 | my PROP $prop = prop(my $glob = shift); | |||||||||||||||||||||||||||
| 555 | $prop->{charset} | ||||||||||||||||||||||||||||
| 556 | 0 | } | |||||||||||||||||||||||||||
| 557 | 495 | ▶ | sub set_charset { | ||||||||||||||||||||||||||
|
Subroutine
set_charset: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 558 | 495 | my PROP $prop = prop(my $glob = shift); | |||||||||||||||||||||||||||
| 559 | 495 | $prop->{charset} = shift; | |||||||||||||||||||||||||||
| 560 | 495 | $glob; | |||||||||||||||||||||||||||
| 561 | } | ||||||||||||||||||||||||||||
| 562 | |||||||||||||||||||||||||||||
| 563 | #======================================== | ||||||||||||||||||||||||||||
| 564 | |||||||||||||||||||||||||||||
| 565 | 0 | ▶ | sub configure_stash { | ||||||||||||||||||||||||||
|
Subroutine
configure_stash: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 566 | 0 | my PROP $prop = prop(my $glob = shift); | |||||||||||||||||||||||||||
| 567 | 0 | my ($value) = @_; | |||||||||||||||||||||||||||
| 568 | 0 | $prop->{_stash} = $value; | |||||||||||||||||||||||||||
| 569 | } | ||||||||||||||||||||||||||||
| 570 | |||||||||||||||||||||||||||||
| 571 | 397 | ▶ | sub stash { | ||||||||||||||||||||||||||
|
Subroutine
stash: called CC=4 SCAR=18.7
Pod
undocumented
| |||||||||||||||||||||||||||||
| 572 | 397 | my PROP $prop = prop(my $glob = shift); | |||||||||||||||||||||||||||
| 573 | 397 | ▶ | unless (@_) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 574 | $prop->{_stash} //= {} | ||||||||||||||||||||||||||||
| 575 | 397 | ▶ | } elsif (@_ == 1) { | ||||||||||||||||||||||||||
|
Condition100%2/2
$prop->{"_stash"} //= {}
MC/DC100%1/1
$prop->{"_stash"} //= {}
$prop->{"_stash"}
Truth table100%2/2
A
A= $prop->{"_stash"}
| |||||||||||||||||||||||||||||
| 576 | 0 | $prop->{_stash}{$_[0]} | |||||||||||||||||||||||||||
| 577 | } else { | ||||||||||||||||||||||||||||
| 578 | 0 | my $name = shift; | |||||||||||||||||||||||||||
| 579 | 0 | $prop->{_stash}{$name} = shift; | |||||||||||||||||||||||||||
| 580 | 0 | $glob; | |||||||||||||||||||||||||||
| 581 | } | ||||||||||||||||||||||||||||
| 582 | } | ||||||||||||||||||||||||||||
| 583 | |||||||||||||||||||||||||||||
| 584 | #======================================== | ||||||||||||||||||||||||||||
| 585 | |||||||||||||||||||||||||||||
| 586 | 3 | ▶ | sub gettext { | ||||||||||||||||||||||||||
|
Subroutine
gettext: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 587 | 3 | my PROP $prop = (my $glob = shift)->prop; | |||||||||||||||||||||||||||
| 588 | 3 | $prop->{yatt}->lang_gettext($prop->{lang}, @_); | |||||||||||||||||||||||||||
| 589 | } | ||||||||||||||||||||||||||||
| 590 | |||||||||||||||||||||||||||||
| 591 | 3 | ▶ | sub ngettext { | ||||||||||||||||||||||||||
|
Subroutine
ngettext: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 592 | 3 | my PROP $prop = (my $glob = shift)->prop; | |||||||||||||||||||||||||||
| 593 | 3 | $prop->{yatt}->lang_ngettext($prop->{lang}, @_); | |||||||||||||||||||||||||||
| 594 | } | ||||||||||||||||||||||||||||
| 595 | |||||||||||||||||||||||||||||
| 596 | #======================================== | ||||||||||||||||||||||||||||
| 597 | |||||||||||||||||||||||||||||
| 598 | 1 | ▶ | sub backend { | ||||||||||||||||||||||||||
|
Subroutine
backend: called CC=5 SCAR=19.6
Pod
undocumented
| |||||||||||||||||||||||||||||
| 599 | 1 | my PROP $prop = (my $glob = shift)->prop; | |||||||||||||||||||||||||||
| 600 | |||||||||||||||||||||||||||||
| 601 | # XXX: Exposing bare backend may harm. | ||||||||||||||||||||||||||||
| 602 | # But anyway, you can get backend via cget('backend'). | ||||||||||||||||||||||||||||
| 603 | # | ||||||||||||||||||||||||||||
| 604 | 1 | ▶ | return $prop->{backend} unless @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 605 | |||||||||||||||||||||||||||||
| 606 | 1 | my $method = shift; | |||||||||||||||||||||||||||
| 607 | 1 | ▶ | unless (defined $method) { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 608 | 0 | $glob->error("backend: null method is called"); | |||||||||||||||||||||||||||
| 609 | } elsif (not $prop->{backend}) { | ||||||||||||||||||||||||||||
| 610 | 0 | $glob->error("backend is empty"); | |||||||||||||||||||||||||||
| 611 | } elsif (not my $sub = $prop->{backend}->can($method)) { | ||||||||||||||||||||||||||||
| 612 | 0 | $glob->error("unknown method called for backend: %s", $method); | |||||||||||||||||||||||||||
| 613 | } else { | ||||||||||||||||||||||||||||
| 614 | 1 | $sub->($prop->{backend}, @_); | |||||||||||||||||||||||||||
| 615 | } | ||||||||||||||||||||||||||||
| 616 | } | ||||||||||||||||||||||||||||
| 617 | |||||||||||||||||||||||||||||
| 618 | { | ||||||||||||||||||||||||||||
| 619 | 73 | foreach (qw/model resultset | |||||||||||||||||||||||||||
| 620 | txn_do txn_begin txn_commit txn_rollback | ||||||||||||||||||||||||||||
| 621 | txn_scope_guard | ||||||||||||||||||||||||||||
| 622 | /) { | ||||||||||||||||||||||||||||
| 623 | 511 | my $method = $_; | |||||||||||||||||||||||||||
| 624 | 511 | ▶ | *{globref(__PACKAGE__, $method)} = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 625 | 1 | my PROP $prop = (my $glob = shift)->prop; | |||||||||||||||||||||||||||
| 626 | 1 | $prop->{backend}->$method(@_); | |||||||||||||||||||||||||||
| 627 | 511 | }; | |||||||||||||||||||||||||||
| 628 | } | ||||||||||||||||||||||||||||
| 629 | } | ||||||||||||||||||||||||||||
| 630 | |||||||||||||||||||||||||||||
| 631 | 73 | 1; | |||||||||||||||||||||||||||