| 1 | package Plack::Middleware::ServerTiming; | ||||||||||||||||||||||||||||
| 2 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 5 | ▶ | use parent qw/Plack::Middleware/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 5 | ▶ | use Plack::Util; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 5 | our $VERSION = "0.04"; | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 4 | ▶ | sub call { | ||||||||||||||||||||||||||
|
Subroutine
call: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 10 | 4 | my ($self, $env) = @_; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 4 | my $res = $self->app->($env); | |||||||||||||||||||||||||||
| 13 | 4 | ▶ | $self->response_cb($res, sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 14 | 4 | my $res = shift; | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 4 | ▶ | return unless exists $env->{'psgix.server-timing'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 3 | my @header; | |||||||||||||||||||||||||||
| 19 | 3 | for my $metric (@{$env->{'psgix.server-timing'}}) { | |||||||||||||||||||||||||||
| 20 | 10 | my $name = $metric->[0]; | |||||||||||||||||||||||||||
| 21 | 10 | ▶ | my %field = %{$metric->[1] || {}}; | ||||||||||||||||||||||||||
|
Condition100%2/2
$metric->[1] || {}
MC/DC100%1/1
$metric->[1] || {}
$metric->[1]
Truth table100%2/2
A
A= $metric->[1]
| |||||||||||||||||||||||||||||
| 22 | 10 | my @opt = map { "$_=" . _escape($field{$_}) } grep { defined $field{$_} } qw/dur desc/; | |||||||||||||||||||||||||||
| 23 | 10 | push @header, join ';', $name, @opt; | |||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | 3 | Plack::Util::header_set($res->[1], 'Server-Timing', join(', ', @header)); | |||||||||||||||||||||||||||
| 26 | 4 | }); | |||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 10 | ▶ | sub _escape { | ||||||||||||||||||||||||||
|
Subroutine
_escape: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 30 | 10 | my $v = shift; | |||||||||||||||||||||||||||
| 31 | 10 | ▶ | if ($v =~ /[\x00-\x20()<>@,;:\\\"\/\[\]?={}\x7F-\xFF]/ || !length($v)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$v =~ m([\x00-\x20()<>\@,;:\\\"/\[\]?={}\x7F-\xFF]) or not length $v
MC/DC50%1/2
$v =~ m([\x00-\x20()<>\@,;:\\\"/\[\]?={}\x7F-\xFF]) or not length $v
$v =~ m([\x00-\x20()<>\@,;:\\\"/\[\]?={}\x7F-\xFF])
not length $v
Truth table66%2/3
A or not(B)
A= $v =~ m([\x00-\x20()<>\@,;:\\\"/\[\]?={}\x7F-\xFF])B= not length $v
| |||||||||||||||||||||||||||||
| 32 | 3 | $v =~ s/([\"\\])/\\$1/g; | |||||||||||||||||||||||||||
| 33 | 3 | return qq{"$v"}; | |||||||||||||||||||||||||||
| 34 | } else { | ||||||||||||||||||||||||||||
| 35 | 7 | return $v; | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 5 | 1; | |||||||||||||||||||||||||||
| 40 | __END__ | ||||||||||||||||||||||||||||