line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::HTTP::Spore::Middleware::Runtime; |
2
|
|
|
|
|
|
|
$Net::HTTP::Spore::Middleware::Runtime::VERSION = '0.07'; |
3
|
|
|
|
|
|
|
# ABSTRACT: add a new header with runtime |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
608
|
use Moose; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
8
|
|
6
|
|
|
|
|
|
|
extends 'Net::HTTP::Spore::Middleware'; |
7
|
1
|
|
|
1
|
|
6357
|
use Time::HiRes; |
|
1
|
|
|
|
|
1037
|
|
|
1
|
|
|
|
|
4
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub call { |
10
|
1
|
|
|
1
|
0
|
3
|
my ( $self, $req) = @_; |
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
|
|
5
|
my $start_time = [Time::HiRes::gettimeofday]; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
$self->response_cb( |
15
|
|
|
|
|
|
|
sub { |
16
|
1
|
|
|
1
|
|
2
|
my $res = shift; |
17
|
1
|
|
|
|
|
5
|
my $req_time = sprintf '%.6f', |
18
|
|
|
|
|
|
|
Time::HiRes::tv_interval($start_time); |
19
|
1
|
|
|
|
|
28
|
$res->header('X-Spore-Runtime' => $req_time); |
20
|
|
|
|
|
|
|
} |
21
|
1
|
|
|
|
|
11
|
); |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
1; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
__END__ |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=pod |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=encoding UTF-8 |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 NAME |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
Net::HTTP::Spore::Middleware::Runtime - add a new header with runtime |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head1 VERSION |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
version 0.07 |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head1 SYNOPSIS |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
my $client = Net::HTTP::Spore->new_from_spec('twitter.json'); |
43
|
|
|
|
|
|
|
$client->enable('Runtime'); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
my $result = $client->public_timeline; |
46
|
|
|
|
|
|
|
say "request executed in ".$result->header('X-Spore-Runtime'); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head1 DESCRIPTION |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
Net::HTTP::Spore::Middleware::Runtime is a middleware that add a new header to the response's headers: X-Spore-Runtime. The value of the header is the time the request took to be executed. |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head1 AUTHORS |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=over 4 |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=item * |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
Franck Cuny <franck.cuny@gmail.com> |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=item * |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
Ash Berlin <ash@cpan.org> |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=item * |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
Ahmad Fatoum <athreef@cpan.org> |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=back |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
This software is copyright (c) 2012 by Linkfluence. |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
75
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=cut |