line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
##---------------------------------------------------------------------------- |
2
|
|
|
|
|
|
|
## Asynchronous HTTP Request and Promise - ~/lib/HTTP/Promise/Headers/ServerTiming.pm |
3
|
|
|
|
|
|
|
## Version v0.1.0 |
4
|
|
|
|
|
|
|
## Copyright(c) 2022 DEGUEST Pte. Ltd. |
5
|
|
|
|
|
|
|
## Author: Jacques Deguest <jack@deguest.jp> |
6
|
|
|
|
|
|
|
## Created 2022/05/08 |
7
|
|
|
|
|
|
|
## Modified 2022/05/08 |
8
|
|
|
|
|
|
|
## All rights reserved. |
9
|
|
|
|
|
|
|
## |
10
|
|
|
|
|
|
|
## |
11
|
|
|
|
|
|
|
## This program is free software; you can redistribute it and/or modify it |
12
|
|
|
|
|
|
|
## under the same terms as Perl itself. |
13
|
|
|
|
|
|
|
##---------------------------------------------------------------------------- |
14
|
|
|
|
|
|
|
package HTTP::Promise::Headers::ServerTiming; |
15
|
|
|
|
|
|
|
BEGIN |
16
|
|
|
|
|
|
|
{ |
17
|
3
|
|
|
3
|
|
3591
|
use strict; |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
91
|
|
18
|
3
|
|
|
3
|
|
15
|
use warnings; |
|
3
|
|
|
|
|
13
|
|
|
3
|
|
|
|
|
88
|
|
19
|
3
|
|
|
3
|
|
16
|
use warnings::register; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
422
|
|
20
|
3
|
|
|
3
|
|
17
|
use parent qw( HTTP::Promise::Headers::Generic ); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
17
|
|
21
|
3
|
|
|
3
|
|
275
|
our $VERSION = 'v0.1.0'; |
22
|
|
|
|
|
|
|
}; |
23
|
|
|
|
|
|
|
|
24
|
3
|
|
|
3
|
|
18
|
use strict; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
60
|
|
25
|
3
|
|
|
3
|
|
14
|
use warnings; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
1265
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub init |
28
|
|
|
|
|
|
|
{ |
29
|
4
|
|
|
4
|
1
|
343402
|
my $self = shift( @_ ); |
30
|
4
|
50
|
66
|
|
|
56
|
@_ = () if( @_ == 1 && $self->_is_a( $_[0] => 'Module::Generic::Null' ) ); |
31
|
4
|
100
|
|
|
|
74
|
if( @_ ) |
32
|
|
|
|
|
|
|
{ |
33
|
2
|
|
|
|
|
9
|
my $this = shift( @_ ); |
34
|
2
|
|
|
|
|
7
|
my $hv; |
35
|
2
|
50
|
|
|
|
13
|
if( index( $this, ';' ) != -1 ) |
36
|
|
|
|
|
|
|
{ |
37
|
2
|
|
|
|
|
30
|
$hv = $self->_parse_header_value( $this ); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
else |
40
|
|
|
|
|
|
|
{ |
41
|
0
|
|
|
|
|
0
|
$hv = $self->_new_hv( $this ); |
42
|
|
|
|
|
|
|
} |
43
|
2
|
50
|
|
|
|
13
|
return( $self->pass_error ) if( !defined( $hv ) ); |
44
|
2
|
|
|
|
|
22
|
my $opts = $self->_get_args_as_hash( @_ ); |
45
|
2
|
|
|
|
|
18
|
$hv->param( $_ => $opts->{ $_ } ) for( keys( %$opts ) ); |
46
|
2
|
|
|
|
|
15
|
$self->_hv( $hv ); |
47
|
|
|
|
|
|
|
} |
48
|
4
|
|
|
|
|
283
|
$self->{_init_strict_use_sub} = 1; |
49
|
4
|
50
|
|
|
|
24
|
$self->SUPER::init( @_ ) || return( $self->pass_error ); |
50
|
4
|
|
|
|
|
28
|
$self->_field_name( 'Server-Timing' ); |
51
|
4
|
|
|
|
|
3336
|
return( $self ); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
4
|
|
|
4
|
1
|
298994
|
sub as_string { return( shift->_hv_as_string( @_ ) ); } |
55
|
|
|
|
|
|
|
|
56
|
3
|
|
|
3
|
1
|
300094
|
sub desc { return( shift->_set_get_param( 'desc', @_ ) ); } |
57
|
|
|
|
|
|
|
|
58
|
3
|
|
|
3
|
1
|
1538
|
sub dur { return( shift->_set_get_param( 'dur', @_ ) ); } |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub name |
61
|
|
|
|
|
|
|
{ |
62
|
3
|
|
|
3
|
1
|
38759
|
my $self = shift( @_ ); |
63
|
3
|
|
|
|
|
14
|
my $hv = $self->_hv; |
64
|
3
|
100
|
|
|
|
99
|
if( @_ ) |
65
|
|
|
|
|
|
|
{ |
66
|
1
|
|
|
|
|
3
|
my $this = shift( @_ ); |
67
|
1
|
50
|
|
|
|
3
|
if( $hv ) |
68
|
|
|
|
|
|
|
{ |
69
|
0
|
|
|
|
|
0
|
$hv->value( $this ); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
else |
72
|
|
|
|
|
|
|
{ |
73
|
1
|
|
|
|
|
11
|
$hv = $self->_new_hv( $this ); |
74
|
1
|
|
|
|
|
222
|
$self->_hv( $hv ); |
75
|
|
|
|
|
|
|
} |
76
|
1
|
|
|
|
|
40
|
return( $this); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
else |
79
|
|
|
|
|
|
|
{ |
80
|
2
|
50
|
|
|
|
11
|
return( '' ) if( !$hv ); |
81
|
2
|
|
|
|
|
18
|
return( $hv->value_data ); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
0
|
|
|
0
|
1
|
|
sub param { return( shift->_set_get_param( @_ ) ); } |
86
|
|
|
|
|
|
|
|
87
|
0
|
|
|
0
|
1
|
|
sub params { return( shift->_set_get_params( @_ ) ); } |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
1; |
90
|
|
|
|
|
|
|
# NOTE: POD |
91
|
|
|
|
|
|
|
__END__ |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=encoding utf-8 |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 NAME |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
HTTP::Promise::Headers::ServerTiming - Server-Timing Header Field |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 SYNOPSIS |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
use HTTP::Promise::Headers::ServerTiming; |
102
|
|
|
|
|
|
|
my $srv = HTTP::Promise::Headers::ServerTiming->new || |
103
|
|
|
|
|
|
|
die( HTTP::Promise::Headers::ServerTiming->error, "\n" ); |
104
|
|
|
|
|
|
|
$srv->name( 'cache' ); |
105
|
|
|
|
|
|
|
$srv->dur(2.4); |
106
|
|
|
|
|
|
|
$srv->desc( 'Cache Read' ); |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 VERSION |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
v0.1.0 |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 DESCRIPTION |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
The following is an extract from Mozilla documentation. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
The Server-Timing header communicates one or more metrics and descriptions for a given request-response cycle. |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
Example: |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
# Single metric without value |
121
|
|
|
|
|
|
|
Server-Timing: missedCache |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
# Single metric with value |
124
|
|
|
|
|
|
|
Server-Timing: cpu;dur=2.4 |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
# Single metric with description and value |
127
|
|
|
|
|
|
|
Server-Timing: cache;desc="Cache Read";dur=23.2 |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
# Two metrics with value |
130
|
|
|
|
|
|
|
Server-Timing: db;dur=53, app;dur=47.2 |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head1 METHODS |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head2 as_string |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
Returns a string representation of the C<Server-Timing> object. |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head2 desc |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
Sets or gets the server timing description. |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head2 dur |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
Sets or gets the duration |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head2 name |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
Sets or gets the server timing metrics name. |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head2 param |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
Set or get an arbitrary name-value pair attribute. |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=head2 params |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
Set or get multiple name-value parameters. |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
Calling this without any parameters, retrieves the associated L<hash object|Module::Generic::Hash> |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head1 AUTHOR |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
Jacques Deguest E<lt>F<jack@deguest.jp>E<gt> |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=head1 SEE ALSO |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Server-Timing> |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
L<HTTP::Promise>, L<HTTP::Promise::Request>, L<HTTP::Promise::Response>, L<HTTP::Promise::Message>, L<HTTP::Promise::Entity>, L<HTTP::Promise::Headers>, L<HTTP::Promise::Body>, L<HTTP::Promise::Body::Form>, L<HTTP::Promise::Body::Form::Data>, L<HTTP::Promise::Body::Form::Field>, L<HTTP::Promise::Status>, L<HTTP::Promise::MIME>, L<HTTP::Promise::Parser>, L<HTTP::Promise::IO>, L<HTTP::Promise::Stream>, L<HTTP::Promise::Exception> |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
Copyright(c) 2022 DEGUEST Pte. Ltd. |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
All rights reserved. |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=cut |