lib/HTTP/Promise/Headers/Cookie.pm

filter: Statementstmt 100% 31 / 31 Branchbran 62.5% 5 / 8 Conditioncond 66.6% 2 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 9 / 9 Podpod 100% 3 / 3 totaltotal 89.2% 50 / 56 CC 6 SCAR 11.7
CC
6
Cov
90%
init
6.2
BEGIN
1.0
BEGIN
1.0
CRAP 3.2
« lib/HTTP/Promise/Headers/KeepAlive.pm ↑ Summary lib/HTTP/Promise/Headers/Forwarded.pm »
1 ##----------------------------------------------------------------------------
2 ## Asynchronous HTTP Request and Promise - ~/lib/HTTP/Promise/Headers/Cookie.pm
3 ## Version v0.1.0
4 ## Copyright(c) 2022 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2022/05/07
7 ## Modified 2022/05/07
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::Cookie;
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 3 ▶ my $self = shift( @_ );
Subroutine init: called CC=6 SCAR=18.3
Pod documented
30 3 $self->{cookies} = [];
31 3 ▶ @_ = () if( @_ == 1 && $self->_is_a( $_[0] => 'Module::Generic::Null' ) );
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 1 and $self->_is_a($_[0], "Module::Generic::Null") 0 3 3
Condition66%2/3
@_ == 1 and $self->_is_a($_[0], "Module::Generic::Null")
!ll&&!rl&&r
120
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 3 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 2 1 3
33 {
34 2 my $this = shift( @_ );
35 2 ▶ my $ref = $self->_is_array( $this ) ? $this : [split( /(?<!\\)\;[[:blank:]\h]*/, $this )];
Branch: 1 branch
BranchTrueFalseTotal
$self->_is_array($this) ? : 0 2 2
36 2 $self->cookies( $ref );
37 }
38 3 $self->{_init_strict_use_sub} = 1;
39 3 ▶ $self->SUPER::init( @_ ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->SUPER::init(@_) or return $self->pass_error 0 3 3
40 3 $self->_field_name( 'Cookie' );
41 3 return( $self );
42 }
43  
44 4 ▶sub as_string { return( shift->cookies->join( '; ' )->scalar ); }
Subroutine as_string: called CC=1 SCAR=0.0
Pod documented
45  
46 10 ▶sub cookies { return( shift->_set_get_array_as_object( 'cookies', @_ ) ); }
Subroutine cookies: called CC=1 SCAR=0.0
Pod documented
47  
48 3 1;
49 # NOTE: POD
50 __END__
51  
52 =encoding utf-8
53  
54 =head1 NAME
55  
56 HTTP::Promise::Headers::Cookie - Cookie Header Field
57  
58 =head1 SYNOPSIS
59  
60 use HTTP::Promise::Headers::Cookie;
61 my $c = HTTP::Promise::Headers::Cookie->new( 'name=value; name2=value2; name3=value3' ) ||
62 die( HTTP::Promise::Headers::Cookie->error, "\n" );
63 # or
64 my $c = HTTP::Promise::Headers::Cookie->new( [qw( name=value name2=value2 name3=value3 )] );
65 $c->cookies->push( 'name4=value4' );
66 $c->cookies->remove( 'name2=value2' );
67 say "$c";
68 # This would return: name=value; name3=value3; name4=value4
69  
70 =head1 VERSION
71  
72 v0.1.0
73  
74 =head1 DESCRIPTION
75  
76 L<HTTP::Promise::Headers::Cookie> implements a simple interface to store the cookie name-value pairs sent by the user agent to the server. It uses L</cookies> which returns a L<Module::Generic::Array> to manage and contain all the cookie name-value pairs. It is up to you to provide the right cookie string.
77  
78 You can and maybe should use L<Cookie::Jar> to help you manage a cookie jar and format cookies.
79  
80 =head1 CONSTRUCTOR
81  
82 =head2 new
83  
84 Provided with an optional string or array reference and this will instantiate a new object and return it.
85  
86 If a string is provided, it is expected to be properly formatted, such as:
87  
88 name=value; name2=value2; name3=value3
89  
90 It will be properly split and added to L</cookies>. If an array is provided, it will be directly added to L</cookies>.
91  
92 =head1 METHODS
93  
94 =head2 as_string
95  
96 Returns a string representation for this C<Cookie> header field.
97  
98 =head2 cookies
99  
100 Returns an L<array object|Module::Generic::Array> containing all the cookies.
101  
102 =head1 THREAD-SAFETY
103  
104 This module is thread-safe for all operations, as it operates on per-object state and uses thread-safe external libraries.
105  
106 =head1 AUTHOR
107  
108 Jacques Deguest E<lt>F<jack@deguest.jp>E<gt>
109  
110 =head1 SEE ALSO
111  
112 L<Cookie>, L<Cookie::Jar>, L<rfc6265, section 5.4|https://tools.ietf.org/html/rfc6265#section-5.4> and L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cookie>
113  
114 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>
115  
116 =head1 COPYRIGHT & LICENSE
117  
118 Copyright(c) 2022 DEGUEST Pte. Ltd.
119  
120 All rights reserved.
121  
122 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
123  
124 =cut
« lib/HTTP/Promise/Headers/KeepAlive.pm ↑ Summary lib/HTTP/Promise/Headers/Forwarded.pm »