AnyUA/Middleware/Runtime.pm

filter: Statementstmt 96.1% 25 / 26 Branchbran 50.0% 1 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 100% 1 / 1 totaltotal 94.2% 33 / 35 SCAR 6.9
CC
2
Cov
93%
request
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 2.0
« AnyUA/Backend.pm ↑ Summary AnyUA/Middleware/RequestHeaders.pm »
1 package HTTP::AnyUA::Middleware::Runtime;
2 # ABSTRACT: Middleware to determine response time
3  
4  
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 our $VERSION = '0.902'; # VERSION
9  
10 2 ▶use parent 'HTTP::AnyUA::Middleware';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 2 ▶use Time::HiRes;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14  
15 sub request {
16 1 ▶ my $self = shift;
Subroutine request: called CC=2 SCAR=7.0
Pod documented
17 1 my ($method, $url, $args) = @_;
18  
19 1 my $start = [Time::HiRes::gettimeofday];
20  
21 1 my $resp = $self->backend->request($method, $url, $args);
22  
23 my $handle_response = sub {
24 1 ▶ my $resp = shift;
Subroutine __ANON__: called CC=1 SCAR=0.0
25  
26 1 $resp->{runtime} = sprintf('%.6f', Time::HiRes::tv_interval($start));
27  
28 1 return $resp;
29 1 };
30  
31 1 ▶ if ($self->response_is_future) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->response_is_future) { } 0 1 1
32 0 $resp->transform(
33 done => $handle_response,
34 fail => $handle_response,
35 );
36 }
37 else {
38 1 $resp = $handle_response->($resp);
39 }
40  
41 1 return $resp;
42 }
43  
44 2 1;
45  
46 __END__
« AnyUA/Backend.pm ↑ Summary AnyUA/Middleware/RequestHeaders.pm »