| 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 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 3 | ▶ | warnings::register_categories( 'HTTP::Promise' ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 3 | ▶ | use parent qw( HTTP::Promise::Headers::Generic ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 3 | our $VERSION = 'v0.1.0'; | |||||||||||||||||||||||||||
| 22 | }; | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | sub init | ||||||||||||||||||||||||||||
| 28 | { | ||||||||||||||||||||||||||||
| 29 | 5 | ▶ | my $self = shift( @_ ); | ||||||||||||||||||||||||||
|
Subroutine
init: called CC=8 SCAR=21.5
Pod
documented
| |||||||||||||||||||||||||||||
| 30 | 5 | ▶ | @_ = () if( @_ == 1 && $self->_is_a( $_[0] => 'Module::Generic::Null' ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@_ == 1 and $self->_is_a($_[0], "Module::Generic::Null")
MC/DC0%0/2
@_ == 1 and $self->_is_a($_[0], "Module::Generic::Null")
@_ == 1
$self->_is_a($_[0], "Module::Generic::Null")
Truth table66%2/3
A and B
A= @_ == 1B= $self->_is_a($_[0], "Module::Generic::Null")
| |||||||||||||||||||||||||||||
| 31 | 5 | ▶ | if( @_ ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | { | ||||||||||||||||||||||||||||
| 33 | 3 | my $this = shift( @_ ); | |||||||||||||||||||||||||||
| 34 | 3 | my $hv; | |||||||||||||||||||||||||||
| 35 | 3 | ▶ | if( index( $this, ';' ) != -1 ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | { | ||||||||||||||||||||||||||||
| 37 | 3 | $hv = $self->_parse_header_value( $this ); | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | else | ||||||||||||||||||||||||||||
| 40 | { | ||||||||||||||||||||||||||||
| 41 | 0 | $hv = $self->_new_hv( $this ); | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | 3 | ▶ | return( $self->pass_error ) if( !defined( $hv ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | 3 | my $opts = $self->_get_args_as_hash( @_ ); | |||||||||||||||||||||||||||
| 45 | 3 | $hv->param( $_ => $opts->{ $_ } ) for( keys( %$opts ) ); | |||||||||||||||||||||||||||
| 46 | 3 | $self->_hv( $hv ); | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | 5 | $self->{_init_strict_use_sub} = 1; | |||||||||||||||||||||||||||
| 49 | 5 | ▶ | $self->SUPER::init( @_ ) || return( $self->pass_error ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | 5 | $self->_field_name( 'Server-Timing' ); | |||||||||||||||||||||||||||
| 51 | 5 | return( $self ); | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 6 | ▶ | sub as_string { return( shift->_hv_as_string( @_ ) ); } | ||||||||||||||||||||||||||
|
Subroutine
as_string: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 5 | ▶ | sub desc { return( shift->_set_get_param( 'desc', @_ ) ); } | ||||||||||||||||||||||||||
|
Subroutine
desc: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 5 | ▶ | sub dur { return( shift->_set_get_param( 'dur', @_ ) ); } | ||||||||||||||||||||||||||
|
Subroutine
dur: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | sub name | ||||||||||||||||||||||||||||
| 61 | { | ||||||||||||||||||||||||||||
| 62 | 5 | ▶ | my $self = shift( @_ ); | ||||||||||||||||||||||||||
|
Subroutine
name: called CC=4 SCAR=14.1
Pod
documented
| |||||||||||||||||||||||||||||
| 63 | 5 | my $hv = $self->_hv; | |||||||||||||||||||||||||||
| 64 | 5 | ▶ | if( @_ ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | { | ||||||||||||||||||||||||||||
| 66 | 1 | my $this = shift( @_ ); | |||||||||||||||||||||||||||
| 67 | 1 | ▶ | if( $hv ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | { | ||||||||||||||||||||||||||||
| 69 | 0 | $hv->value( $this ); | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | else | ||||||||||||||||||||||||||||
| 72 | { | ||||||||||||||||||||||||||||
| 73 | 1 | $hv = $self->_new_hv( $this ); | |||||||||||||||||||||||||||
| 74 | 1 | $self->_hv( $hv ); | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | 1 | return( $this); | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | else | ||||||||||||||||||||||||||||
| 79 | { | ||||||||||||||||||||||||||||
| 80 | 4 | ▶ | return( '' ) if( !$hv ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | 4 | return( $hv->value_data ); | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 0 | ▶ | sub param { return( shift->_set_get_param( @_ ) ); } | ||||||||||||||||||||||||||
|
Subroutine
param: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 0 | ▶ | sub params { return( shift->_set_get_params( @_ ) ); } | ||||||||||||||||||||||||||
|
Subroutine
params: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 3 | 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 THREAD-SAFETY | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | This module is thread-safe for all operations, as it operates on per-object state and uses thread-safe external libraries. | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | Jacques Deguest E<lt>F<jack@deguest.jp>E<gt> | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Server-Timing> | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | 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> | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | =head1 COPYRIGHT & LICENSE | ||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | Copyright(c) 2022 DEGUEST Pte. Ltd. | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | All rights reserved. | ||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | =cut | ||||||||||||||||||||||||||||