Promise/Headers/AltSvc.pm

filter: Statementstmt 54.5% 42 / 77 Branchbran 25.0% 10 / 40 Conditioncond 42.1% 8 / 19 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 61.1% 11 / 18 Podpod 100% 9 / 9 totaltotal 46.2% 80 / 173 CC 28 SCAR 38.8
CC
28
Cov
44%
alternative
156.0
protocol
19.8
init
14.6
CRAP 48.6
« Promise/Body/Form/Field.pm ↑ Summary Promise/Headers/Generic.pm »
1 ##----------------------------------------------------------------------------
2 ## Asynchronous HTTP Request and Promise - ~/lib/HTTP/Promise/Headers/AltSvc.pm
3 ## Version v0.1.0
4 ## Copyright(c) 2022 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2022/05/06
7 ## Modified 2022/05/06
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::AltSvc;
15 BEGIN
16 3 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
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' );
20 3 ▶ use parent qw( HTTP::Promise::Headers::Generic );
Subroutine BEGIN: called CC=1 SCAR=0.0
21 3 ▶ use URI::Escape::XS ();
Subroutine BEGIN: called CC=1 SCAR=0.0
22 3 our $VERSION = 'v0.1.0';
23 };
24  
25 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 sub init
29 5 ▶{
Subroutine init: called CC=12 SCAR=26.8
Pod documented
30 5 my $self = shift( @_ );
31 5 ▶ @_ = () if( @_ == 1 && $self->_is_a( $_[0] => 'Module::Generic::Null' ) );
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 1 and $self->_is_a($_[0], "Module::Generic::Null") 0 5 5
Condition66%2/3
@_ == 1 and $self->_is_a($_[0], "Module::Generic::Null")
!ll&&!rl&&r
140
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")
ABresult
0X0
100
111
32 5 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 4 1 5
33 {
34 4 my $this = shift( @_ );
35 4 my $params = $self->_get_args_as_hash( @_ );
36 4 ▶ unless( ( $self->_is_array( $this ) && scalar( @$this ) == 2 ) ||
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_is_array($this) and scalar @$this == 2 or not ref $this or overload::Method($this, "''")) 0 4 4
Condition55%5/9
$self->_is_array($this) and scalar @$this == 2 or not ref $this or overload::Method($this, "''")
l!l&&r!l&&!r
400
$self->_is_array($this) and scalar @$this == 2 or not ref $this
l!l&&r!l&&!r
130
$self->_is_array($this) and scalar @$this == 2
!ll&&!rl&&r
301
MC/DC0%0/4
$self->_is_array($this) and scalar @$this == 2 or not ref $this or overload::Method($this, "''")
$self->_is_array($this) scalar @$this == 2 not ref $this overload::Method($this, "''")
Truth table28%2/7
A and B or not(C) or D
A= $self->_is_array($this)B= scalar @$this == 2C= not ref $thisD= overload::Method($this, "''")
ABCDresult
11XX1
0X1X1
101X1
0X011
10011
0X000
10000
37 !ref( $this ) ||
38 overload::Method( $this, "''" ) )
39 {
40 0 return( $self->error( "Wrong alternate server name-value provided '$this'. I was expecting either a name=value string or an array reference with 2 elements." ) );
41 }
42 4 ▶ my $hv = $self->_is_array( $this ) ? $self->_new_hv( $this ) : $self->_parse_header_value( $this );
Branch: 1 branch
BranchTrueFalseTotal
$self->_is_array($this) ? : 1 3 4
43 4 ▶ return( $self->pass_error ) if( !defined( $hv ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $hv 0 4 4
44 4 ▶ $hv->_set_get_params( $params ) if( scalar( keys( %$params ) ) );
Branch: 1 branch
BranchTrueFalseTotal
if scalar keys %$params 0 4 4
45 4 $hv->encode(1);
46 4 $self->_hv( $hv );
47 }
48 5 $self->{_init_strict_use_sub} = 1;
49 5 ▶ $self->SUPER::init( @_ ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->SUPER::init(@_) or return $self->pass_error 5 0 5
50 5 $self->_field_name( 'Alt-Svc' );
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 sub alternative
57 0 ▶{
Subroutine alternative: not called CC=12 SCAR=50.5
Pod documented
58 0 my $self = shift( @_ );
59 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
60 {
61 0 ▶ return( $self->error( "Bad arguments provided. Usage: \$h->alternative( \$proto, \$auth )" ) ) if( @_ > 2 );
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 2 0 0 0
62 0 ▶ my( $proto, $auth ) = @_ > 1 ? @_[0,1] : $_[0];
Branch: 1 branch
BranchTrueFalseTotal
@_ > 1 ? : 0 0 0
63 # need escaping?
64 0 ▶ if( @_ == 1 )
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1) 0 0 0
65 {
66 0 ▶ return( $self->error( "Bad argument provided. You need to provide a protocol=authority." ) ) if( index( $proto, '=' ) == -1 );
Branch: 1 branch
BranchTrueFalseTotal
if (index($proto, "=") == -1) 0 0 0
67 0 ( $proto, $auth ) = split( /=/, $proto, 2 );
68 0 ▶ $proto = $self->_unescape( $proto ) if( $proto =~ /\%(?=\d{2})/ );
Branch: 1 branch
BranchTrueFalseTotal
if $proto =~ /\%(?=\d{2})/ 0 0 0
69 }
70 0 my $hv;
71 0 ▶ if( $hv = $self->_hv )
Branch: 1 branch
BranchTrueFalseTotal
if ($hv = $self->_hv) { } 0 0 0
72 {
73 0 $hv->value( [ $proto, $auth ] );
74 }
75 else
76 {
77 0 $hv = $self->_new_hv( [ $proto, $auth ] );
78 0 $hv->encode(1);
79 0 $self->_hv( $hv );
80 }
81 }
82 else
83 {
84 0 ▶ my $hv = $self->_hv || return( '' );
Condition0%0/2
$self->_hv || (return '')
l!l
00
MC/DC0%0/1
$self->_hv || (return '')
$self->_hv
Truth table0%0/2
A
A= $self->_hv
Aresult
11
00
85 0 my $ref = $hv->value;
86 0 ▶ return( wantarray() ? () : '' ) if( $ref->is_empty );
Branch: 2 branches
BranchTrueFalseTotal
if $ref->is_empty 0 0 0
wantarray ? : 0 0 0
87 0 ▶ return( $ref->list ) if( wantarray() );
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 0 0 0
88 0 my( $proto, $auth ) = $ref->list;
89 # $proto = $self->_escape( $proto );
90 0 $proto = $hv->token_escape( $proto );
91 0 return( join( '=', $proto, $auth ) );
92 }
93 }
94  
95 # This needs a protocol to be set first
96 2 ▶sub authority { return( shift->_hv->value_data( @_ ) ); }
Subroutine authority: called CC=1 SCAR=0.0
Pod documented
97  
98 0 ▶sub ma { return( shift->_set_get_param( ma => @_ ) ); }
Subroutine ma: not called CC=1 SCAR=6.9
Pod documented
99  
100 0 ▶sub param { return( shift->_set_get_param( @_ ) ); }
Subroutine param: not called CC=1 SCAR=6.9
Pod documented
101  
102 0 ▶sub params { return( shift->_set_get_params( @_ ) ); }
Subroutine params: not called CC=1 SCAR=6.9
Pod documented
103  
104 0 ▶sub persist { return( shift->_set_get_param( persist => @_ ) ); }
Subroutine persist: not called CC=1 SCAR=6.9
Pod documented
105  
106 sub protocol
107 2 ▶{
Subroutine protocol: called CC=6 SCAR=29.9
Pod documented
108 2 my $self = shift( @_ );
109 2 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 2 2
110 {
111 0 my $proto = shift( @_ );
112 0 ▶ return( $self->error( "Value provided for protocol is empty." ) ) if( !defined( $proto ) || !length( "$proto" ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $proto and length "$proto" 0 0 0
Condition0%0/3
defined $proto and length "$proto"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $proto and length "$proto"
defined $proto length "$proto"
Truth table0%0/3
A and B
A= defined $protoB= length "$proto"
ABresult
0X0
100
111
113 0 my $hv = $self->_hv;
114 0 ▶ if( $hv )
Branch: 1 branch
BranchTrueFalseTotal
if ($hv) { } 0 0 0
115 {
116 0 $hv->value_name( $proto );
117 }
118 else
119 {
120 0 $hv = $self->_new_hv( $proto );
121 0 $self->_hv( $hv );
122 }
123 }
124 else
125 {
126 2 ▶ my $hv = $self->_hv || return( '' );
Condition50%1/2
$self->_hv || (return '')
l!l
20
MC/DC0%0/1
$self->_hv || (return '')
$self->_hv
Truth table50%1/2
A
A= $self->_hv
Aresult
11
00
127 2 return( $hv->value_name );
128 }
129 }
130  
131 # As per rfc7838, section 3: <https://tools.ietf.org/html/rfc7838#section-3>
132 # sub _escape
133 # {
134 # my $self = shift( @_ );
135 # my $v = shift( @_ );
136 # $v =~ s/([=:%]+)/sprintf("%%%02X", ord($1))/ge;
137 # return( $v );
138 # }
139 0 ▶sub _escape { return( URI::Escape::XS::uri_escape( $_[1] ) ); }
Subroutine _escape: not called CC=1 SCAR=6.9
140  
141 # sub _unescape
142 # {
143 # my $self = shift( @_ );
144 # my $v = shift( @_ );
145 # $v =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg;
146 # return( $v );
147 # }
148 0 ▶sub _unescape { return( URI::Escape::XS::uri_unescape( $_[1] ) ); }
Subroutine _unescape: not called CC=1 SCAR=6.9
149  
150 3 1;
151 # NOTE: POD
152 __END__
« Promise/Body/Form/Field.pm ↑ Summary Promise/Headers/Generic.pm »