line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTTP::AnyUA::Middleware::Runtime; |
2
|
|
|
|
|
|
|
# ABSTRACT: Middleware to determine response time |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
458
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
33
|
|
6
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.902'; # VERSION |
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
5
|
use parent 'HTTP::AnyUA::Middleware'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
529
|
use Time::HiRes; |
|
1
|
|
|
|
|
1367
|
|
|
1
|
|
|
|
|
4
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub request { |
16
|
1
|
|
|
1
|
1
|
3
|
my $self = shift; |
17
|
1
|
|
|
|
|
30
|
my ($method, $url, $args) = @_; |
18
|
|
|
|
|
|
|
|
19
|
1
|
|
|
|
|
7
|
my $start = [Time::HiRes::gettimeofday]; |
20
|
|
|
|
|
|
|
|
21
|
1
|
|
|
|
|
4
|
my $resp = $self->backend->request($method, $url, $args); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
my $handle_response = sub { |
24
|
1
|
|
|
1
|
|
2
|
my $resp = shift; |
25
|
|
|
|
|
|
|
|
26
|
1
|
|
|
|
|
2
|
$resp->{runtime} = sprintf('%.6f', Time::HiRes::tv_interval($start)); |
27
|
|
|
|
|
|
|
|
28
|
1
|
|
|
|
|
51
|
return $resp; |
29
|
1
|
|
|
|
|
18
|
}; |
30
|
|
|
|
|
|
|
|
31
|
1
|
50
|
|
|
|
3
|
if ($self->response_is_future) { |
32
|
0
|
|
|
|
|
0
|
$resp->transform( |
33
|
|
|
|
|
|
|
done => $handle_response, |
34
|
|
|
|
|
|
|
fail => $handle_response, |
35
|
|
|
|
|
|
|
); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
else { |
38
|
1
|
|
|
|
|
2
|
$resp = $handle_response->($resp); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
1
|
|
|
|
|
6
|
return $resp; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
1; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
__END__ |