lib/HTTP/Promise/Headers/StrictTransportSecurity.pm

filter: Statementstmt 97.6% 42 / 43 Branchbran 50.0% 5 / 10 Conditioncond 66.6% 2 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 93.3% 14 / 15 Podpod 100% 9 / 9 totaltotal 87.8% 72 / 82 CC 8 SCAR 12.3
CC
8
Cov
88%
init
7.1
property
6.0
BEGIN
1.0
CRAP 3.4
« blib/lib/HTTP/Promise/Headers/ContentSecurityPolicy.pm ↑ Summary lib/HTTP/Promise/Headers/KeepAlive.pm »
1 ##----------------------------------------------------------------------------
2 ## Asynchronous HTTP Request and Promise - ~/lib/HTTP/Promise/Headers/StrictTransportSecurity.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::StrictTransportSecurity;
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=7 SCAR=19.7
Pod documented
30 5 $self->{properties} = {};
31 5 $self->{params} = [];
32 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
230
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
33 5 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 3 2 5
34 {
35 3 my $this = shift( @_ );
36 3 ▶ my $ref = $self->new_array( $self->_is_array( $this ) ? $this : [split( /[[:blank:]\h]*(?<!\\)\;[[:blank:]\h]*/, "$this" )] );
Branch: 1 branch
BranchTrueFalseTotal
$self->_is_array($this) ? : 0 3 3
37 3 my $params = $self->params;
38 3 my $props = $self->properties;
39 3 foreach my $pair ( @$ref )
40 {
41 9 my( $prop, $val ) = split( /=/, $pair, 2 );
42 9 $props->{ $prop } = $val;
43 9 $params->push( $prop );
44 }
45 }
46 5 $self->{_init_strict_use_sub} = 1;
47 5 ▶ $self->SUPER::init( @_ ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->SUPER::init(@_) or return $self->pass_error 0 5 5
48 5 $self->_field_name( 'Strict-Transport-Security' );
49 5 return( $self );
50 }
51  
52 7 ▶sub as_string { return( shift->_set_get_properties_as_string( sep => ';' ) ); }
Subroutine as_string: called CC=1 SCAR=0.0
Pod documented
53  
54 7 ▶sub include_subdomains { return( shift->_set_get_property_boolean( 'includeSubDomains', @_ ) ); }
Subroutine include_subdomains: called CC=1 SCAR=0.0
Pod documented
55  
56 7 ▶sub max_age { return( shift->_set_get_property_number( 'max-age', @_ ) ); }
Subroutine max_age: called CC=1 SCAR=0.0
Pod documented
57  
58 32 ▶sub params { return( shift->_set_get_array_as_object( 'params', @_ ) ); }
Subroutine params: called CC=1 SCAR=0.0
Pod documented
59  
60 0 ▶sub property { return( shift->_set_get_property_value( @_, ( @_ > 1 ? { needs_quotes => 1 } : () ) ) ); }
Subroutine property: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
@_ > 1 ? : 0 0 0
61  
62 1 ▶sub property_boolean { return( shift->_set_get_property_boolean( @_ ) ); }
Subroutine property_boolean: called CC=1 SCAR=0.0
Pod documented
63  
64 32 ▶sub properties { return( shift->_set_get_hash_as_mix_object( 'properties', @_ ) ); }
Subroutine properties: called CC=1 SCAR=0.0
Pod documented
65  
66 7 ▶sub preload { return( shift->_set_get_property_boolean( 'preload', @_ ) ); }
Subroutine preload: called CC=1 SCAR=0.0
Pod documented
67  
68 3 1;
69 # NOTE: POD
70 __END__
71  
72 =encoding utf-8
73  
74 =head1 NAME
75  
76 HTTP::Promise::Headers::StrictTransportSecurity - Strict-Transport-Security Header Field
77  
78 =head1 SYNOPSIS
79  
80 use HTTP::Promise::Headers::StrictTransportSecurity;
81 my $sts = HTTP::Promise::Headers::StrictTransportSecurity->new ||
82 die( HTTP::Promise::Headers::StrictTransportSecurity->error, "\n" );
83 $sts->include_subdomains(1);
84 $sts->max_age(63072000);
85 $sts->preload(1);
86 say "$sts";
87 # same thing
88 say $sts->as_string;
89  
90 =head1 VERSION
91  
92 v0.1.0
93  
94 =head1 DESCRIPTION
95  
96 The following is an extract from Mozilla documentation.
97  
98 The HTTP Strict-Transport-Security response header (often abbreviated as HSTS) informs browsers that the site should only be accessed using HTTPS, and that any future attempts to access it using HTTP should automatically be converted to HTTPS.
99  
100 Example:
101  
102 Strict-Transport-Security: max-age=63072000; includeSubDomains; preload
103  
104 =head1 METHODS
105  
106 =head2 as_string
107  
108 Returns a string representation of the C<Strict-Transport-Security> object.
109  
110 =head2 include_subdomains
111  
112 Boolean, optional. If provided with a true value, the parameter C<includeSubDomains> will be added.
113  
114 If this optional parameter is enabled, this means that this rule applies to all of the site's subdomains as well.
115  
116 =head2 max_age
117  
118 Integer, required value (but not enforced).
119  
120 The time, in seconds, that the browser should remember that a site is only to be accessed using HTTPS.
121  
122 =head2 param
123  
124 Set or get an arbitrary name-value pair attribute.
125  
126 =head2 params
127  
128 Set or get multiple name-value parameters.
129  
130 Calling this without any parameters, retrieves the associated L<hash object|Module::Generic::Hash>
131  
132 =head2 preload
133  
134 Boolean, optional. If provided with a true value, the parameter C<preload> will be added.
135  
136 =head2 property
137  
138 Sets or gets an arbitrary property.
139  
140 $h->property( community => 'UCI' );
141 my $val = $h->property( 'community' );
142  
143 See also L<rfc7234, section 5.2.3|https://httpwg.org/specs/rfc7234.html#rfc.section.5.2.3>
144  
145 =head2 property_boolean
146  
147 Sets or gets an arbitrary boolean property.
148  
149 $h->property_boolean( private_property => 1 );
150  
151 =head2 properties
152  
153 Returns the L<hash object|Module::Generic::hash> used as a repository of properties.
154  
155 =head1 THREAD-SAFETY
156  
157 This module is thread-safe for all operations, as it operates on per-object state and uses thread-safe external libraries.
158  
159 =head1 AUTHOR
160  
161 Jacques Deguest E<lt>F<jack@deguest.jp>E<gt>
162  
163 =head1 SEE ALSO
164  
165 See also L<rfc6797, section 6.1|https://tools.ietf.org/html/rfc6797#section-6.1> and L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Strict-Transport-Security>
166  
167 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>
168  
169 =head1 COPYRIGHT & LICENSE
170  
171 Copyright(c) 2022 DEGUEST Pte. Ltd.
172  
173 All rights reserved.
174  
175 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
176  
177 =cut
« blib/lib/HTTP/Promise/Headers/ContentSecurityPolicy.pm ↑ Summary lib/HTTP/Promise/Headers/KeepAlive.pm »