| 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.904'; # 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 | 2 | ▶ | sub request { | ||||||||
|
Subroutine
request: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 16 | 2 | my $self = shift; | |||||||||
| 17 | 2 | my ($method, $url, $args) = @_; | |||||||||
| 18 | |||||||||||
| 19 | 2 | my $start = [Time::HiRes::gettimeofday]; | |||||||||
| 20 | |||||||||||
| 21 | 2 | my $resp = $self->backend->request($method, $url, $args); | |||||||||
| 22 | |||||||||||
| 23 | 2 | ▶ | my $handle_response = sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 24 | 2 | my $resp = shift; | |||||||||
| 25 | |||||||||||
| 26 | 2 | $resp->{runtime} = sprintf('%.6f', Time::HiRes::tv_interval($start)); | |||||||||
| 27 | |||||||||||
| 28 | 2 | return $resp; | |||||||||
| 29 | 2 | }; | |||||||||
| 30 | |||||||||||
| 31 | 2 | ▶ | if ($self->response_is_future) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 32 | 1 | $resp = $resp->transform( | |||||||||
| 33 | done => $handle_response, | ||||||||||
| 34 | fail => $handle_response, | ||||||||||
| 35 | ); | ||||||||||
| 36 | } | ||||||||||
| 37 | else { | ||||||||||
| 38 | 1 | $resp = $handle_response->($resp); | |||||||||
| 39 | } | ||||||||||
| 40 | |||||||||||
| 41 | 2 | return $resp; | |||||||||
| 42 | } | ||||||||||
| 43 | |||||||||||
| 44 | 2 | 1; | |||||||||
| 45 | |||||||||||
| 46 | __END__ | ||||||||||