Cookie/Jar.pm

filter: Statementstmt 28.9% 338 / 1166 Branchbran 13.7% 97 / 706 Conditioncond 14.0% 88 / 625 MC/DCmcdc 3.6% 12 / 328 Subroutinesub 54.5% 42 / 77 Podpod 100% 41 / 41 totaltotal 21.0% 618 / 2943 CC 627 SCAR 66.8
CC
627
Cov
21%
save_as_mozilla
2919.4
add_request_header
1332.0
extract
1016.1
CRAP 794.7
↑ Summary Cookie/Domain.pm »
1 ##----------------------------------------------------------------------------
2 ## Cookies API for Server & Client - ~/lib/Cookie/Jar.pm
3 ## Version v0.4.0
4 ## Copyright(c) 2025 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2019/10/08
7 ## Modified 2026/11/12
8 ## You can use, copy, modify and redistribute this package and associated
9 ## files under the same terms as Perl itself.
10 ##----------------------------------------------------------------------------
11 package Cookie::Jar;
12 BEGIN
13 8 ▶{
Subroutine BEGIN: called CC=3 SCAR=11.2
14 8 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 8 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 8 ▶ use warnings::register;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 8 ▶ use parent qw( Module::Generic );
Subroutine BEGIN: called CC=1 SCAR=0.0
18 8 ▶ use vars qw( $VERSION $COOKIES_DEBUG $MOD_PERL $MOD_PERL_VERSION $LIVE_JARS );
Subroutine BEGIN: called CC=1 SCAR=0.0
19 8 our( $MOD_PERL, $MOD_PERL_VERSION );
20 8 ▶ if( exists( $ENV{MOD_PERL} )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $ENV{"MOD_PERL"} and $Cookie::Jar::MOD_PERL = $ENV{"MOD_PERL"} =~ m[^mod_perl/(\d+\.[\d\.]+)]) 0 8 8
Condition33%1/3
exists $ENV{"MOD_PERL"} and $Cookie::Jar::MOD_PERL = $ENV{"MOD_PERL"} =~ m[^mod_perl/(\d+\.[\d\.]+)]
!ll&&!rl&&r
800
MC/DC0%0/2
exists $ENV{"MOD_PERL"} and $Cookie::Jar::MOD_PERL = $ENV{"MOD_PERL"} =~ m[^mod_perl/(\d+\.[\d\.]+)]
exists $ENV{"MOD_PERL"} $Cookie::Jar::MOD_PERL = $ENV{"MOD_PERL"} =~ m[^mod_perl/(\d+\.[\d\.]+)]
Truth table33%1/3
A and B
A= exists $ENV{"MOD_PERL"}B= $Cookie::Jar::MOD_PERL = $ENV{"MOD_PERL"} =~ m[^mod_perl/(\d+\.[\d\.]+)]
ABresult
0X0
100
111
21 &&
22 ( $MOD_PERL = $ENV{MOD_PERL} =~ /^mod_perl\/(\d+\.[\d\.]+)/ ) )
23 {
24 0 $MOD_PERL_VERSION = $1;
25 0 select( ( select( STDOUT ), $| = 1 )[0] );
26 0 require Apache2::Const;
27 0 Apache2::Const->import( compile => qw( :common :http OK DECLINED ) );
28 0 require APR::Pool;
29 0 require APR::Table;
30 0 require Apache2::RequestUtil;
31 0 require APR::Request::Apache2;
32 0 require APR::Request::Cookie;
33 }
34 8 ▶ use Cookie;
Subroutine BEGIN: called CC=1 SCAR=0.0
35 8 ▶ use Cookie::Domain;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 8 ▶ use DateTime::Lite;
Subroutine BEGIN: called CC=1 SCAR=0.0
37 8 ▶ use DateTime::Format::Lite;
Subroutine BEGIN: called CC=1 SCAR=0.0
38 8 ▶ use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
39 8 ▶ use Module::Generic::HeaderValue;
Subroutine BEGIN: called CC=1 SCAR=0.0
40 8 ▶ use Scalar::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
41 8 ▶ use URI::Escape ();
Subroutine BEGIN: called CC=1 SCAR=0.0
42 8 our $VERSION = 'v0.4.0';
43 # This flag to allow extensive debug message to be enabled
44 8 our $COOKIES_DEBUG = 0;
45 # Global registry of cookies stored with a weak reference to avoid interfering with their destruction.
46 # This is used to autosave cookie jars during the END phase, before global destruction.
47 8 our $LIVE_JARS = {};
48 8 ▶ use constant CRYPTX_VERSION => '0.074';
Subroutine BEGIN: called CC=1 SCAR=0.0
49 };
50  
51 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
52 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
53  
54 sub init
55 7 ▶{
Subroutine init: called CC=11 SCAR=30.2
Pod documented
56 7 my $self = shift( @_ );
57 # Apache2::RequestRec object
58 7 my $req;
59 7 ▶ $req = shift( @_ ) if( @_ && ( @_ % 2 ) );
Branch: 1 branch
BranchTrueFalseTotal
if @_ and @_ % 2 0 7 7
Condition66%2/3
@_ and @_ % 2
!ll&&!rl&&r
250
MC/DC0%0/2
@_ and @_ % 2
@_ @_ % 2
Truth table66%2/3
A and B
A= @_B= @_ % 2
ABresult
0X0
100
111
60 # For decryption and encryption
61 7 $self->{algo} = undef;
62 # If a cookie file is provided, yes, we'll automatically load and save from and to it.
63 7 $self->{autosave} = 1;
64 # For decryption and encryption
65 7 $self->{encrypt} = 0;
66 7 $self->{file} = '';
67 7 $self->{host} = '';
68 # For decryption and encryption
69 7 $self->{iv} = undef;
70 # For decryption and encryption
71 7 $self->{secret} = undef;
72 # Cookie file type; can also be 'lwp' or 'netscape'
73 7 $self->{type} = 'json';
74 7 $self->{_init_strict_use_sub} = 1;
75 7 $self->SUPER::init( @_ );
76 7 ▶ $self->{request} = $req if( $req );
Branch: 1 branch
BranchTrueFalseTotal
if $req 0 7 7
77 # Flag to ensure we are ready to autosave cookies, when the init phase has succeeded.
78 7 $self->{_autosave_ready} = 0;
79 # Flag to avoid repeat of autosave upon global destruction.
80 7 $self->{_autosaved} = 0;
81 # Repository of all objects
82 7 $self->{_cookies} = [];
83 # Index by host, path, name
84 7 $self->{_index} = {};
85 7 my $file = $self->file;
86 7 ▶ if( $file && $file->exists && !$file->is_empty )
Branch: 1 branch
BranchTrueFalseTotal
if ($file and $file->exists and not $file->is_empty) 0 7 7
Condition33%2/6
$file and $file->exists and not $file->is_empty
!ll&&!rl&&r
700
$file and $file->exists
!ll&&!rl&&r
700
MC/DC0%0/3
$file and $file->exists and not $file->is_empty
$file $file->exists not $file->is_empty
Truth table25%1/4
A and B and not(C)
A= $fileB= $file->existsC= not $file->is_empty
ABCresult
0XX0
10X0
1100
1111
87 {
88 0 my $encrypt = $self->encrypt;
89 0 my $type = $self->type;
90 0 my $type2sub =
91 {
92 json => \&load,
93 lwp => \&load_as_lwp,
94 netscape => \&load_as_netscape,
95 };
96 0 ▶ return( $self->error( "Unknown cookie jar type '$type'. This can be either json, lwp or netscape" ) ) if( !CORE::exists( $type2sub->{ $type } ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $type2sub->{$type} 0 0 0
97 0 my $loader = $type2sub->{ $type };
98  
99 0 ▶ if( $encrypt )
Branch: 1 branch
BranchTrueFalseTotal
if ($encrypt) { } 0 0 0
100 {
101 0 ▶ $loader->( $self, $file,
Branch: 1 branch
BranchTrueFalseTotal
&$loader($self, $file, "algo", $self->algo, "key", $self->secret) or return $self->pass_error 0 0 0
102 algo => $self->algo,
103 key => $self->secret,
104 ) || return( $self->pass_error );
105 }
106 else
107 {
108 0 ▶ $loader->( $self, $file ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
&$loader($self, $file) or return $self->pass_error 0 0 0
109 }
110 }
111 # Cookies are now safe to autosave. Without this protection, the autosave would
112 # potentially overwrite the file with an empty jar.
113 7 $self->{_autosave_ready} = 1;
114 7 my $addr = Scalar::Util::refaddr( $self );
115 7 $LIVE_JARS->{ $addr } = $self;
116 7 Scalar::Util::weaken( $LIVE_JARS->{ $addr } );
117 7 return( $self );
118 }
119  
120 sub add
121 6 ▶{
Subroutine add: called CC=17 SCAR=46.3
Pod documented
122 6 my $self = shift( @_ );
123 6 my $this;
124 6 ▶ if( scalar( @_ ) == 1 )
Branch: 2 branches
BranchTrueFalseTotal
if (scalar @_ == 1) { } 6 0 6
elsif (scalar @_) { } 0 0 0
125 {
126 6 $this = shift( @_ );
127 }
128 elsif( scalar( @_ ) )
129 {
130 0 $this = $self->_get_args_as_hash( @_ );
131 }
132 else
133 {
134 0 return( $self->error( "No data was provided to add a cookie in the repository." ) );
135 }
136  
137 6 ▶ if( ref( $this ) eq 'HASH' )
Branch: 3 branches
BranchTrueFalseTotal
if (ref $this eq 'HASH') { } 6 0 6
elsif (not ref $this) { } 0 0 0
elsif (not $self->_is_object($this) or $self->_is_object($this) and not $this->isa('Cookie')) { } 0 0 0
138 {
139 6 $this = $self->make( $this );
140 6 ▶ return( $self->pass_error ) if( !defined( $this ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $this 0 6 6
141 }
142 # A string ?
143 elsif( !ref( $this ) )
144 {
145 0 ▶ my $hv = Module::Generic::HeaderValue->new_from_header( $this, decode => 1, debug => $self->debug ) ||
Condition0%0/2
'Module::Generic::HeaderValue'->new_from_header($this, 'decode', 1, 'debug', $self->debug) || (return $self->error('Module::Generic::HeaderValue'->error))
l!l
00
MC/DC0%0/1
'Module::Generic::HeaderValue'->new_from_header($this, 'decode', 1, 'debug', $self->debug) || (return $self->error('Module::Generic::HeaderValue'->error))
'Module::Generic::HeaderValue'->new_from_header($this, 'decode', 1, 'debug', $self->debug)
Truth table0%0/2
A
A= 'Module::Generic::HeaderValue'->new_from_header($this, 'decode', 1, 'debug', $self->debug)
Aresult
11
00
146 return( $self->error( Module::Generic::HeaderValue->error ) );
147 0 my $ref = {};
148 0 $ref->{name} = $hv->value->first;
149 0 $ref->{value} = $hv->value->second;
150 $hv->params->foreach(sub
151 0 ▶ {
Subroutine __ANON__: not called CC=1 SCAR=6.9
152 0 my( $n, $v ) = @_;
153 0 $ref->{ $n } = $v;
154 0 return(1);
155 0 });
156 0 ▶ $ref->{secure} = 1 if( CORE::exists( $ref->{secure} ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $ref->{"secure"} 0 0 0
157 # In case those were provided too in the cookie line
158 0 ▶ $ref->{samesite} = 1 if( CORE::exists( $ref->{samesite} ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $ref->{"samesite"} 0 0 0
159 0 ▶ $ref->{httponly} = 1 if( CORE::exists( $ref->{httponly} ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $ref->{"httponly"} 0 0 0
160 0 $this = $self->make( %$ref );
161 0 ▶ return( $self->pass_error ) if( !defined( $this ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $this 0 0 0
162 }
163 ▶ elsif( !$self->_is_object( $this ) ||
Condition0%0/6
not $self->_is_object($this) or $self->_is_object($this) and not $this->isa("Cookie")
l!l&&r!l&&!r
000
$self->_is_object($this) and not $this->isa("Cookie")
!ll&&!rl&&r
000
MC/DC0%0/3
not $self->_is_object($this) or $self->_is_object($this) and not $this->isa("Cookie")
not $self->_is_object($this) $self->_is_object($this) not $this->isa("Cookie")
Truth table0%0/4
not(A) or B and not(C)
A= not $self->_is_object($this)B= $self->_is_object($this)C= not $this->isa("Cookie")
ABCresult
1XX1
0111
00X0
0100
164 ( $self->_is_object( $this ) && !$this->isa( 'Cookie' ) ) )
165 {
166 0 return( $self->error( "I was expecting an hash reference or a Cookie object, but instead I got '$this'." ) );
167 }
168 6 my $ref = $self->_cookies;
169 6 my $idx = $self->_index;
170 6 ▶ $this->name or return( $self->error( "No cookie name was set in this cookie." ) );
Branch: 1 branch
BranchTrueFalseTotal
$this->name or return $self->error("No cookie name was set in this cookie.") 6 0 6
171 6 ▶ my $key = $self->key( $this ) || return( $self->pass_error );
Condition50%1/2
$self->key($this) || (return $self->pass_error)
l!l
60
MC/DC0%0/1
$self->key($this) || (return $self->pass_error)
$self->key($this)
Truth table50%1/2
A
A= $self->key($this)
Aresult
11
00
172 6 $ref->push( $this );
173 6 ▶ $idx->{ $key } = [] if( !CORE::exists( $idx->{ $key } ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $idx->{$key} 6 0 6
174 6 push( @{$idx->{ $key }}, $this );
175 6 return( $this );
176 }
177  
178 0 ▶sub add_cookie_header { return( shift->add_request_header( @_ ) ); }
Subroutine add_cookie_header: not called CC=1 SCAR=6.9
Pod documented
179  
180 sub add_request_header
181 0 ▶{
Subroutine add_request_header: not called CC=36 SCAR=71.9
Pod documented
182 0 my $self = shift( @_ );
183 0 ▶ my $req = shift( @_ ) || return( $self->error( "No request object was provided." ) );
Condition0%0/2
shift @_ || (return $self->error('No request object was provided.'))
l!l
00
MC/DC0%0/1
shift @_ || (return $self->error('No request object was provided.'))
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
184 0 ▶ return( $self->error( "Request object provided is not an object." ) ) if( !Scalar::Util::blessed( $req ) );
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($req) 0 0 0
185 0 ▶ return( $self->error( "Request object provided does not support the uri or header methods." ) ) if( !$req->can( 'uri' ) || !$req->can( 'header' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $req->can("uri") and $req->can("header") 0 0 0
Condition0%0/3
$req->can("uri") and $req->can("header")
!ll&&!rl&&r
000
MC/DC0%0/2
$req->can("uri") and $req->can("header")
$req->can("uri") $req->can("header")
Truth table0%0/3
A and B
A= $req->can("uri")B= $req->can("header")
ABresult
0X0
100
111
186 0 ▶ my $uri = $req->uri || return( $self->error( "No uri set in the request object." ) );
Condition0%0/2
$req->uri || (return $self->error('No uri set in the request object.'))
l!l
00
MC/DC0%0/1
$req->uri || (return $self->error('No uri set in the request object.'))
$req->uri
Truth table0%0/2
A
A= $req->uri
Aresult
11
00
187 0 my $scheme = $uri->scheme;
188 0 ▶ unless( $scheme =~ /^https?\z/ )
Branch: 1 branch
BranchTrueFalseTotal
unless ($scheme =~ /^https?\z/) 0 0 0
189 {
190 0 return( '' );
191 }
192 0 my( $host, $port, $path );
193 0 ▶ if( $host = $req->header( 'Host' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($host = $req->header('Host')) { } 0 0 0
194 {
195 0 $host =~ s/:(\d+)$//;
196 0 $host = lc( $host );
197 0 $port = $1;
198 }
199 else
200 {
201 0 $host = lc( $uri->host );
202 }
203 0 ▶ my $is_secure = ( $scheme eq 'https' ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
$scheme eq 'https' ? : 0 0 0
204 # URI::URL method
205 0 ▶ if( $uri->can( 'epath' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($uri->can('epath')) { } 0 0 0
206 {
207 0 $path = $uri->epath;
208 }
209 else
210 {
211 # URI::_generic method
212 0 $path = $uri->path;
213 }
214 0 ▶ $path = '/' unless( CORE::length( $path ) );
Branch: 1 branch
BranchTrueFalseTotal
unless CORE::length $path 0 0 0
215 0 ▶ $port = $uri->port if( !defined( $port ) || !CORE::length( $port ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $port and CORE::length $port 0 0 0
Condition0%0/3
defined $port and CORE::length $port
!ll&&!rl&&r
000
MC/DC0%0/2
defined $port and CORE::length $port
defined $port CORE::length $port
Truth table0%0/3
A and B
A= defined $portB= CORE::length $port
ABresult
0X0
100
111
216 # my $now = time();
217 0 my $now = DateTime::Lite->now;
218 0 ▶ $path = $self->_normalize_path( $path ) if( CORE::index( $path, '%' ) != -1 );
Branch: 1 branch
BranchTrueFalseTotal
if (index($path, "%") != -1) 0 0 0
219 0 my $root;
220 0 ▶ if( $self->_is_ip( $host ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_ip($host)) { } 0 0 0
221 {
222 0 $root = $host;
223 }
224 else
225 {
226 0 ▶ my $dom = Cookie::Domain->new || return( $self->pass_error( Cookie::Domain->error ) );
Condition0%0/2
'Cookie::Domain'->new || (return $self->pass_error('Cookie::Domain'->error))
l!l
00
MC/DC0%0/1
'Cookie::Domain'->new || (return $self->pass_error('Cookie::Domain'->error))
'Cookie::Domain'->new
Truth table0%0/2
A
A= 'Cookie::Domain'->new
Aresult
11
00
227 0 my $res = $dom->stat( $host );
228 0 ▶ return( $self->pass_error( $dom->error ) ) if( !defined( $res ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $res 0 0 0
229 0 ▶ if( !CORE::length( $res ) || ( $res && !$res->domain->length ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not CORE::length $res or $res and not $res->domain->length) 0 0 0
Condition0%0/6
not CORE::length $res or $res and not $res->domain->length
l!l&&r!l&&!r
000
$res and not $res->domain->length
!ll&&!rl&&r
000
MC/DC0%0/3
not CORE::length $res or $res and not $res->domain->length
not CORE::length $res $res not $res->domain->length
Truth table0%0/4
not(A) or B and not(C)
A= not CORE::length $resB= $resC= not $res->domain->length
ABCresult
1XX1
0111
00X0
0100
230 {
231 0 return( $self->error( "No root domain found for host \"$host\"." ) );
232 }
233 0 $root = $res->domain;
234 }
235 # rfc6265, section 5.4
236 # "Either:
237 # The cookie's host-only-flag is true and the canonicalized request-host is identical to the cookie's domain.
238 # Or:
239 # The cookie's host-only-flag is false and the canonicalized request-host domain-matches the cookie's domain."
240 # Meaning, $host is, for example, www.example.or.jp and cookie domain was not set and defaulted to example.or.jp, then it matches; or
241 # cookie domain was explicitly set to www.example.or.jp and matches www.example.or.jp
242 # <https://datatracker.ietf.org/doc/html/rfc6265#section-5.4>
243 # cookie values for the "Cookie" header
244 0 my @values = ();
245 0 my @ok_cookies = ();
246 # Get all cookies for the canonicalised request-host and its sub domains, then we check each one found according to rfc6265 algorithm as stated above
247 0 my $cookies = $self->get_by_domain( $root, with_subdomain => 1 );
248 # Ref: rfc6265, section 5.4
249 # <https://datatracker.ietf.org/doc/html/rfc6265#section-5.4>
250 0 foreach my $c ( @$cookies )
251 {
252 0 ▶ unless( ( $c->host_only && $root eq $c->domain ) ||
Branch: 1 branch
BranchTrueFalseTotal
unless ($c->host_only and $root eq $c->domain or not $c->host_only and $self->_domain_match($host, $c->domain)) 0 0 0
Condition0%0/9
$c->host_only and $root eq $c->domain or not $c->host_only and $self->_domain_match($host, $c->domain)
l!l&&r!l&&!r
000
$c->host_only and $root eq $c->domain
!ll&&!rl&&r
000
not $c->host_only and $self->_domain_match($host, $c->domain)
!ll&&!rl&&r
000
MC/DC0%0/4
$c->host_only and $root eq $c->domain or not $c->host_only and $self->_domain_match($host, $c->domain)
$c->host_only $root eq $c->domain not $c->host_only $self->_domain_match($host, $c->domain)
Truth table0%0/7
A and B or not(C) and D
A= $c->host_onlyB= $root eq $c->domainC= not $c->host_onlyD= $self->_domain_match($host, $c->domain)
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
253 ( !$c->host_only && $self->_domain_match( $host, $c->domain ) ) )
254 {
255 0 next;
256 }
257 0 ▶ if( index( $path, $c->path ) != 0 )
Branch: 4 branches
BranchTrueFalseTotal
if (index($path, $c->path) != 0) { } 0 0 0
elsif (not $is_secure and $c->secure) { } 0 0 0
elsif ($c->expires and $c->expires < $now) { } 0 0 0
elsif ($c->port and $c->port != $port) { } 0 0 0
258 {
259 0 next;
260 }
261 ▶ elsif( !$is_secure && $c->secure )
Condition0%0/3
not $is_secure and $c->secure
!ll&&!rl&&r
000
MC/DC0%0/2
not $is_secure and $c->secure
not $is_secure $c->secure
Truth table0%0/3
not(A) and B
A= not $is_secureB= $c->secure
ABresult
0X0
100
111
262 {
263 0 next;
264 }
265 # elsif( $c->expires && $c->expires->epoch < $now )
266 ▶ elsif( $c->expires && $c->expires < $now )
Condition0%0/3
$c->expires and $c->expires < $now
!ll&&!rl&&r
000
MC/DC0%0/2
$c->expires and $c->expires < $now
$c->expires $c->expires < $now
Truth table0%0/3
A and B
A= $c->expiresB= $c->expires < $now
ABresult
0X0
100
111
267 {
268 0 next;
269 }
270 ▶ elsif( $c->port && $c->port != $port )
Condition0%0/3
$c->port and $c->port != $port
!ll&&!rl&&r
000
MC/DC0%0/2
$c->port and $c->port != $port
$c->port $c->port != $port
Truth table0%0/3
A and B
A= $c->portB= $c->port != $port
ABresult
0X0
100
111
271 {
272 0 next;
273 }
274 0 push( @ok_cookies, $c );
275 }
276  
277 # sort cookies by path and by creation date.
278 # Ref: rfc6265, section 5.4.2:
279 # "Cookies with longer paths are listed before cookies with shorter paths."
280 # "Among cookies that have equal-length path fields, cookies with earlier creation-times are listed before cookies with later creation-times."
281 # <https://datatracker.ietf.org/doc/html/rfc6265#section-5.4>
282 # The OR here actually means AND, since the <=> comparison returns false when 2 elements are equal
283 # So when 2 path are the same, we differentiate them by their creation date
284 0 ▶ foreach my $c ( sort{ $b->path->length <=> $a->path->length || $a->created_on <=> $b->created_on } @ok_cookies )
Condition0%0/3
$b->path->length <=> $a->path->length || $a->created_on <=> $b->created_on
l!l&&r!l&&!r
000
MC/DC0%0/2
$b->path->length <=> $a->path->length || $a->created_on <=> $b->created_on
$b->path->length <=> $a->path->length $a->created_on <=> $b->created_on
Truth table0%0/3
A || B
A= $b->path->length <=> $a->path->lengthB= $a->created_on <=> $b->created_on
ABresult
1X1
011
000
285 {
286 0 push( @values, $c->as_string({ is_request => 1 }) );
287 # rfc6265, section 5.4.3
288 # <https://datatracker.ietf.org/doc/html/rfc6265#section-5.4>
289 # "Update the last-access-time of each cookie in the cookie-list to the current date and time."
290 0 $c->accessed_on( time() );
291 }
292  
293 0 ▶ if( @values )
Branch: 1 branch
BranchTrueFalseTotal
if (@values) 0 0 0
294 {
295 0 ▶ if( my $old = $req->header( 'Cookie' ) )
Branch: 1 branch
BranchTrueFalseTotal
if (my $old = $req->header("Cookie")) 0 0 0
296 {
297 0 unshift( @values, $old );
298 }
299 0 $req->header( Cookie => join( '; ', @values ) );
300 }
301 0 return( $req );
302 }
303  
304 sub add_response_header
305 0 ▶{
Subroutine add_response_header: not called CC=12 SCAR=50.5
Pod documented
306 0 my $self = shift( @_ );
307 0 my $resp = shift( @_ );
308 0 my $r = $self->request;
309 0 ▶ if( $resp )
Branch: 1 branch
BranchTrueFalseTotal
if ($resp) 0 0 0
310 {
311 0 ▶ return( $self->error( "Request object provided is not an object." ) ) if( !$self->_is_object( $resp ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_object($resp) 0 0 0
312 0 ▶ return( $self->error( "Request object provided does not support the header methods." ) ) if( !$resp->can( 'header' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $resp->can("header") 0 0 0
313 }
314 0 my @values = ();
315 0 my $ref = $self->_cookies;
316 0 foreach my $c ( sort{ $a->path->length <=> $b->path->length } @$ref )
317 {
318 0 $c->debug( $self->debug );
319 0 ▶ if( $c->discard )
Branch: 1 branch
BranchTrueFalseTotal
if ($c->discard) 0 0 0
320 {
321 0 next;
322 }
323  
324 0 ▶ if( $resp )
Branch: 2 branches
BranchTrueFalseTotal
if ($resp) { } 0 0 0
elsif ($r) { } 0 0 0
325 {
326 0 $resp->headers->push_header( 'Set-Cookie' => "$c" );
327 }
328 elsif( $r )
329 {
330 # APR::Table
331 # We use 'add' and not 'set'
332 0 $r->err_headers_out->add( 'Set-Cookie' => "$c" );
333 }
334 else
335 {
336 0 push( @values, "Set-Cookie: $c" );
337 }
338 }
339 0 ▶ if( @values )
Branch: 1 branch
BranchTrueFalseTotal
if (@values) 0 0 0
340 {
341 0 ▶ return( wantarray() ? @values : join( "\015\012", @values ) );
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
342 }
343 # We return our object only if a response object or an Apache2::RequestRec was set
344 # because otherwise if the user is expecting the cookie as a returned string,
345 # we do not want to return our object instead when there is no cookie to return.
346 0 ▶ return( $self ) if( $r || $resp );
Branch: 1 branch
BranchTrueFalseTotal
if $r or $resp 0 0 0
Condition0%0/3
$r or $resp
l!l&&r!l&&!r
000
MC/DC0%0/2
$r or $resp
$r $resp
Truth table0%0/3
A or B
A= $rB= $resp
ABresult
1X1
011
000
347 0 return( '' );
348 }
349  
350 # NOTE: the algorithm used, if any, to decrypt or encrypt the cookie jar file
351 0 ▶sub algo { return( shift->_set_get_scalar( 'algo', @_ ) ); }
Subroutine algo: not called CC=1 SCAR=6.9
Pod documented
352  
353 7 ▶sub autosave { return( shift->_set_get_boolean( 'autosave', @_ ) ); }
Subroutine autosave: called CC=1 SCAR=0.0
Pod documented
354  
355 sub delete
356 0 ▶{
Subroutine delete: not called CC=24 SCAR=63.1
Pod documented
357 0 my $self = shift( @_ );
358 8 ▶ no overloading;
Subroutine BEGIN: called CC=1 SCAR=0.0
359 0 my $ref = $self->_cookies;
360 0 my $idx = $self->_index;
361 0 ▶ if( scalar( @_ ) == 1 && $self->_is_a( $_[0], 'Cookie' ) )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ == 1 and $self->_is_a($_[0], 'Cookie')) { } 0 0 0
Condition0%0/3
scalar @_ == 1 and $self->_is_a($_[0], "Cookie")
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @_ == 1 and $self->_is_a($_[0], "Cookie")
scalar @_ == 1 $self->_is_a($_[0], "Cookie")
Truth table0%0/3
A and B
A= scalar @_ == 1B= $self->_is_a($_[0], "Cookie")
ABresult
0X0
100
111
362 {
363 0 my $c = shift( @_ );
364 0 my $addr = Scalar::Util::refaddr( $c );
365 0 my $removed = $self->new_array;
366 0 ▶ for( my $i = 0; $i < scalar( @$ref ); $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @$ref) 0 0 0
367 {
368 0 my $this = $ref->[$i];
369 0 ▶ if( Scalar::Util::refaddr( $this ) eq $addr )
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::refaddr($this) eq $addr) 0 0 0
370 {
371 0 my $key = $self->key( $this );
372 0 ▶ if( CORE::exists( $idx->{ $key } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $idx->{$key}) 0 0 0
373 {
374 # if( !$self->_is_array( $idx->{ $key } ) )
375 0 ▶ if( Scalar::Util::reftype( $idx->{ $key } ) ne 'ARRAY' )
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::reftype($idx->{$key}) ne "ARRAY") 0 0 0
376 {
377 0 ▶ return( $self->error( "I was expecting an array for key '$key', but got '", overload::StrVal( $idx->{ $key } // 'undef' ), "' (", ref( $idx->{ $key } ), ")" ) );
Condition0%0/2
$idx->{$key} // "undef"
l!l
00
MC/DC0%0/1
$idx->{$key} // "undef"
$idx->{$key}
Truth table0%0/2
A
A= $idx->{$key}
Aresult
11
00
378 }
379 0 ▶ for( my $j = 0; $j < scalar( @{$idx->{ $key }} ); $j++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($j < scalar @{$idx->{$key};}) 0 0 0
380 {
381 0 ▶ if( Scalar::Util::refaddr( $idx->{ $key }->[$j] ) eq $addr )
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::refaddr($idx->{$key}[$j]) eq $addr) 0 0 0
382 {
383 0 CORE::splice( @{$idx->{ $key }}, $j, 1 );
384 0 $j--;
385 }
386 }
387 # Cleanup
388 0 ▶ CORE::delete( $idx->{ $key } ) if( scalar( @{$idx->{ $key }} ) == 0 );
Branch: 1 branch
BranchTrueFalseTotal
if scalar @{$idx->{$key};} == 0 0 0 0
389 }
390 0 CORE::splice( @$ref, $i, 1 );
391 0 $i--;
392 0 $removed->push( $c );
393 }
394 }
395 0 return( $removed );
396 }
397 else
398 {
399 0 my( $name, $host, $path ) = @_;
400 0 ▶ $host ||= $self->host || '';
Condition0%0/5
$host ||= $self->host || ""
l!l&&r!l&&!r
000
$self->host || ''
l!l
00
MC/DC0%0/2
$host ||= $self->host || ""
$host $self->host
Truth table0%0/3
A ||= B
A= $hostB= $self->host
ABresult
1X1
011
000
401 0 ▶ $path //= '';
Condition0%0/2
$path //= ""
l!l
00
MC/DC0%0/1
$path //= ""
$path
Truth table0%0/2
A
A= $path
Aresult
11
00
402 0 ▶ return( $self->error( "No cookie object provided nor any cookie name either." ) ) if( !defined( $name ) || !CORE::length( "$name" ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name and CORE::length "$name" 0 0 0
Condition0%0/3
defined $name and CORE::length "$name"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $name and CORE::length "$name"
defined $name CORE::length "$name"
Truth table0%0/3
A and B
A= defined $nameB= CORE::length "$name"
ABresult
0X0
100
111
403 0 my $key = $self->key( $name => $host, $path );
404 0 my $removed = $self->new_array;
405 0 ▶ return( $removed ) if( !CORE::exists( $idx->{ $key } ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $idx->{$key} 0 0 0
406 0 ▶ return( $self->error( "I was expecting an array for key '$key', but got '", overload::StrVal( $idx->{ $key } // 'undef' ), "'" ) ) if( !$self->_is_array( $idx->{ $key } ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_array($idx->{$key}) 0 0 0
Condition0%0/2
$idx->{$key} // "undef"
l!l
00
MC/DC0%0/1
$idx->{$key} // "undef"
$idx->{$key}
Truth table0%0/2
A
A= $idx->{$key}
Aresult
11
00
407 0 $removed->push( @{$idx->{ $key }} );
408 0 foreach my $c ( @$removed )
409 {
410 0 ▶ next if( !ref( $c ) || !$self->_is_a( $c, 'Cookie' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $c and $self->_is_a($c, "Cookie") 0 0 0
Condition0%0/3
ref $c and $self->_is_a($c, "Cookie")
!ll&&!rl&&r
000
MC/DC0%0/2
ref $c and $self->_is_a($c, "Cookie")
ref $c $self->_is_a($c, "Cookie")
Truth table0%0/3
A and B
A= ref $cB= $self->_is_a($c, "Cookie")
ABresult
0X0
100
111
411 0 my $addr = Scalar::Util::refaddr( $c );
412 0 ▶ for( my $i = 0; $i < scalar( @$ref ); $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @$ref) 0 0 0
413 {
414 0 ▶ if( Scalar::Util::refaddr( $ref->[$i] ) eq $addr )
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::refaddr($ref->[$i]) eq $addr) 0 0 0
415 {
416 0 CORE::splice( @$ref, $i, 1 );
417 0 last;
418 }
419 }
420 }
421 # Remove cookie and return the previous entry
422 0 CORE::delete( $idx->{ $key } );
423 0 return( $removed );
424 }
425 }
426  
427 sub do
428 2 ▶{
Subroutine do: called CC=9 SCAR=24.4
Pod documented
429 2 my $self = shift( @_ );
430 2 ▶ my $code = shift( @_ ) || return( $self->error( "No callback code was provided." ) );
Condition50%1/2
shift @_ || (return $self->error('No callback code was provided.'))
l!l
20
MC/DC0%0/1
shift @_ || (return $self->error('No callback code was provided.'))
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
431 2 ▶ return( $self->error( "Callback code provided is not a code." ) ) if( ref( $code ) ne 'CODE' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $code ne "CODE" 0 2 2
432 2 my $ref = $self->_cookies->clone;
433 2 my $all = $self->new_array;
434 2 foreach my $c ( @$ref )
435 {
436 4 ▶ next if( !ref( $c ) || !$self->_is_a( $c, 'Cookie' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $c and $self->_is_a($c, "Cookie") 0 4 4
Condition33%1/3
ref $c and $self->_is_a($c, "Cookie")
!ll&&!rl&&r
004
MC/DC0%0/2
ref $c and $self->_is_a($c, "Cookie")
ref $c $self->_is_a($c, "Cookie")
Truth table33%1/3
A and B
A= ref $cB= $self->_is_a($c, "Cookie")
ABresult
0X0
100
111
437 # try-catch
438 4 local $@;
439 eval
440 4 {
441 4 local $_ = $c;
442 4 my $rv = $code->( $c );
443 4 ▶ if( !defined( $rv ) )
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $rv) { } 0 4 4
elsif ($rv) { } 4 0 4
444 {
445 0 last;
446 }
447 elsif( $rv )
448 {
449 4 $all->push( $c );
450 }
451 };
452 4 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 4 4
453 {
454 0 return( $self->error( "An unexpected error occurred while calling code reference on cookie named \"", $ref->{ $c }->name, "\": $@" ) );
455 }
456 }
457 2 return( $all );
458 }
459  
460 # NOTE: Should we decrypt or encrypt the cookie jar file?
461 0 ▶sub encrypt { return( shift->_set_get_boolean( 'encrypt', @_ ) ); }
Subroutine encrypt: not called CC=1 SCAR=6.9
Pod documented
462  
463 sub exists
464 0 ▶{
Subroutine exists: not called CC=7 SCAR=40.3
Pod documented
465 0 my $self = shift( @_ );
466 0 my( $name, $host, $path ) = @_;
467 0 ▶ $host ||= $self->host || '';
Condition0%0/5
$host ||= $self->host || ""
l!l&&r!l&&!r
000
$self->host || ''
l!l
00
MC/DC0%0/2
$host ||= $self->host || ""
$host $self->host
Truth table0%0/3
A ||= B
A= $hostB= $self->host
ABresult
1X1
011
000
468 0 ▶ $path //= '';
Condition0%0/2
$path //= ""
l!l
00
MC/DC0%0/1
$path //= ""
$path
Truth table0%0/2
A
A= $path
Aresult
11
00
469 0 ▶ return( $self->error( "No cookie name was provided to check if it exists." ) ) if( !defined( $name ) || !CORE::length( $name ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name and CORE::length $name 0 0 0
Condition0%0/3
defined $name and CORE::length $name
!ll&&!rl&&r
000
MC/DC0%0/2
defined $name and CORE::length $name
defined $name CORE::length $name
Truth table0%0/3
A and B
A= defined $nameB= CORE::length $name
ABresult
0X0
100
111
470 0 my $c = $self->get( $name => $host, $path );
471 0 ▶ return( defined( $c ) ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
defined $c ? : 0 0 0
472 }
473  
474 # From http client point of view
475 sub extract
476 1 ▶{
Subroutine extract: called CC=46 SCAR=69.2
Pod documented
477 1 my $self = shift( @_ );
478 1 ▶ my $resp = shift( @_ ) || return( $self->error( "No response object was provided." ) );
Condition50%1/2
shift @_ || (return $self->error('No response object was provided.'))
l!l
10
MC/DC0%0/1
shift @_ || (return $self->error('No response object was provided.'))
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
479 1 ▶ return( $self->error( "Response object provided is not an object." ) ) if( !Scalar::Util::blessed( $resp ) );
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($resp) 0 1 1
480 1 my $uri;
481 1 ▶ if( $self->_is_a( $resp, 'HTTP::Response' ) )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_is_a($resp, 'HTTP::Response')) { } 1 0 1
elsif ($resp->can('uri') and $resp->can('header')) { } 0 0 0
482 {
483 1 my $req = $resp->request;
484 1 ▶ return( $self->error( "No HTTP::Request object is set in this HTTP::Response." ) ) if( !$resp->request );
Branch: 1 branch
BranchTrueFalseTotal
unless $resp->request 0 1 1
485 1 $uri = $resp->request->uri;
486 }
487 ▶ elsif( $resp->can( 'uri' ) && $resp->can( 'header' ) )
Condition0%0/3
$resp->can("uri") and $resp->can("header")
!ll&&!rl&&r
000
MC/DC0%0/2
$resp->can("uri") and $resp->can("header")
$resp->can("uri") $resp->can("header")
Truth table0%0/3
A and B
A= $resp->can("uri")B= $resp->can("header")
ABresult
0X0
100
111
488 {
489 0 $uri = $resp->uri;
490 }
491 else
492 {
493 0 return( $self->error( "Response object provided does not support the uri or scheme methods and is not a class or subclass of HTTP::Response either." ) );
494 }
495 1 ▶ my $all = Module::Generic::HeaderValue->new_from_multi( [$resp->header( 'Set-Cookie' )], debug => $self->debug, decode => 1 ) ||
Condition50%1/2
'Module::Generic::HeaderValue'->new_from_multi([$resp->header('Set-Cookie')], 'debug', $self->debug, 'decode', 1) || (return $self->pass_error('Module::Generic::HeaderValue'->error))
l!l
10
MC/DC0%0/1
'Module::Generic::HeaderValue'->new_from_multi([$resp->header('Set-Cookie')], 'debug', $self->debug, 'decode', 1) || (return $self->pass_error('Module::Generic::HeaderValue'->error))
'Module::Generic::HeaderValue'->new_from_multi([$resp->header('Set-Cookie')], 'debug', $self->debug, 'decode', 1)
Truth table50%1/2
A
A= 'Module::Generic::HeaderValue'->new_from_multi([$resp->header('Set-Cookie')], 'debug', $self->debug, 'decode', 1)
Aresult
11
00
496 return( $self->pass_error( Module::Generic::HeaderValue->error ) );
497 1 ▶ return( $resp ) unless( $all->length );
Branch: 1 branch
BranchTrueFalseTotal
unless $all->length 0 1 1
498 1 ▶ $uri || return( $self->error( "No uri set in the response object." ) );
Branch: 1 branch
BranchTrueFalseTotal
$uri or return $self->error("No uri set in the response object.") 1 0 1
499 1 my( $host, $port, $path );
500 1 ▶ if( $host = $resp->header( 'Host' ) ||
Branch: 1 branch
BranchTrueFalseTotal
if ($host = $resp->header('Host') || $resp->request && ($host = $resp->request->header('Host'))) { } 1 0 1
Condition33%2/6
$resp->header('Host') || $resp->request && ($host = $resp->request->header('Host'))
l!l&&r!l&&!r
010
$resp->request and $host = $resp->request->header("Host")
!ll&&!rl&&r
001
MC/DC0%0/3
$resp->header('Host') || $resp->request && ($host = $resp->request->header('Host'))
$resp->header('Host') $resp->request $host = $resp->request->header("Host")
Truth table25%1/4
A || B and C
A= $resp->header('Host')B= $resp->requestC= $host = $resp->request->header("Host")
ABCresult
1XX1
0111
00X0
0100
501 ( $resp->request && ( $host = $resp->request->header( 'Host' ) ) ) )
502 {
503 1 ▶ if( $host =~ s/:(\d+)$// )
Branch: 1 branch
BranchTrueFalseTotal
if ($host =~ s/:(\d+)$//) 0 1 1
504 {
505 0 $port = $1;
506 }
507 1 $host = lc( $host );
508 }
509 else
510 {
511 0 $host = lc( $uri->host );
512 }
513  
514 # URI::URL method
515 1 ▶ if( $uri->can( 'epath' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($uri->can('epath')) { } 0 1 1
516 {
517 0 $path = $uri->epath;
518 }
519 else
520 {
521 # URI::_generic method
522 1 $path = $uri->path;
523 }
524 1 ▶ $path = '/' unless( CORE::length( $path ) );
Branch: 1 branch
BranchTrueFalseTotal
unless CORE::length $path 0 1 1
525 1 ▶ $port = $uri->port if( !defined( $port ) || !CORE::length( $port ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $port and CORE::length $port 1 0 1
Condition33%1/3
defined $port and CORE::length $port
!ll&&!rl&&r
100
MC/DC0%0/2
defined $port and CORE::length $port
defined $port CORE::length $port
Truth table33%1/3
A and B
A= defined $portB= CORE::length $port
ABresult
0X0
100
111
526 1 my $root;
527 1 ▶ if( $self->_is_ip( $host ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_ip($host)) { } 0 1 1
528 {
529 0 $root = $host;
530 }
531 else
532 {
533 1 ▶ my $dom = Cookie::Domain->new || return( $self->pass_error( Cookie::Domain->error ) );
Condition0%0/2
'Cookie::Domain'->new || (return $self->pass_error('Cookie::Domain'->error))
l!l
00
MC/DC0%0/1
'Cookie::Domain'->new || (return $self->pass_error('Cookie::Domain'->error))
'Cookie::Domain'->new
Truth table0%0/2
A
A= 'Cookie::Domain'->new
Aresult
11
00
534 0 my $res = $dom->stat( $host );
535 0 ▶ if( !defined( $res ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $res) 0 0 0
536 {
537 0 return( $self->pass_error( $dom->error ) );
538 }
539 # Possibly empty
540 0 ▶ $root = $res ? $res->domain : '';
Branch: 1 branch
BranchTrueFalseTotal
$res ? : 0 0 0
541 }
542  
543 0 foreach my $o ( @$all )
544 {
545 0 my( $name, $value ) = $o->value->list;
546 0 ▶ my $c = Cookie->new( name => $name, value => $value ) ||
Condition0%0/2
'Cookie'->new('name', $name, 'value', $value) || (return $self->pass_error('Cookie'->error))
l!l
00
MC/DC0%0/1
'Cookie'->new('name', $name, 'value', $value) || (return $self->pass_error('Cookie'->error))
'Cookie'->new('name', $name, 'value', $value)
Truth table0%0/2
A
A= 'Cookie'->new('name', $name, 'value', $value)
Aresult
11
00
547 return( $self->pass_error( Cookie->error ) );
548 0 ▶ if( CORE::length( $o->param( 'expires' ) ) )
Branch: 2 branches
BranchTrueFalseTotal
if (CORE::length $o->param('expires')) { } 0 0 0
elsif (CORE::length $o->param('max-age')) { } 0 0 0
549 {
550 0 my $dt = $self->_parse_timestamp( $o->param( 'expire' ) );
551 0 ▶ if( $dt )
Branch: 1 branch
BranchTrueFalseTotal
if ($dt) { } 0 0 0
552 {
553 0 $c->expires( $dt );
554 }
555 else
556 {
557 0 $c->expires( $o->param( 'expires' ) );
558 }
559 }
560 elsif( CORE::length( $o->param( 'max-age' ) ) )
561 {
562 0 $c->max_age( $o->param( 'max-age' ) );
563 }
564  
565 0 ▶ if( $o->param( 'domain' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($o->param('domain')) { } 0 0 0
566 {
567 # rfc6265, section 5.2.3:
568 # "If the first character of the attribute-value string is %x2E ("."): Let cookie-domain be the attribute-value without the leading %x2E (".") character."
569 # Ref: <https://datatracker.ietf.org/doc/html/rfc6265#section-5.2.3>
570 0 my $c_dom = $o->param( 'domain' );
571 # Remove leading dot as per rfc specifications
572 0 $c_dom =~ s/^\.//g;
573 # "Convert the cookie-domain to lower case."
574 0 $c_dom = lc( $c_dom );
575 # Check the domain name is legitimate, i.e. sent from a host that has authority
576 # "The user agent will reject cookies unless the Domain attribute specifies a scope for the cookie that would include the origin server. For example, the user agent will accept a cookie with a Domain attribute of "example.com" or of "foo.example.com" from foo.example.com, but the user agent will not accept a cookie with a Domain attribute of "bar.example.com" or of "baz.foo.example.com"."
577 # <https://tools.ietf.org/html/rfc6265#section-4.1.2.3>
578 0 ▶ if( CORE::length( $c_dom ) >= CORE::length( $root ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (CORE::length $c_dom >= CORE::length $root and $c_dom eq $host || $host =~ /\.$c_dom$/) { } 0 0 0
Condition0%0/6
CORE::length $c_dom >= CORE::length $root and $c_dom eq $host || $host =~ /\.$c_dom$/
!ll&&!rl&&r
000
$c_dom eq $host or $host =~ /\.$c_dom$/
l!l&&r!l&&!r
000
MC/DC0%0/3
CORE::length $c_dom >= CORE::length $root and $c_dom eq $host || $host =~ /\.$c_dom$/
CORE::length $c_dom >= CORE::length $root $c_dom eq $host $host =~ /\.$c_dom$/
Truth table0%0/4
A and B or C
A= CORE::length $c_dom >= CORE::length $rootB= $c_dom eq $hostC= $host =~ /\.$c_dom$/
ABCresult
0XX0
1000
11X1
1011
579 ( $c_dom eq $host || $host =~ /\.$c_dom$/ ) )
580 {
581 0 $c->domain( $c_dom );
582 }
583 else
584 {
585 0 next;
586 }
587 }
588 # "If omitted, defaults to the host of the current document URL, not including subdomains."
589 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie>
590 else
591 {
592 0 ▶ if( $root )
Branch: 1 branch
BranchTrueFalseTotal
if ($root) { } 0 0 0
593 {
594 0 $c->domain( $root );
595 0 $c->implicit(1);
596 }
597 else
598 {
599 }
600 }
601  
602 # rfc6265: "If the server omits the Path attribute, the user agent will use the "directory" of the request-uri's path component as the default value."
603 0 ▶ if( defined( $o->param( 'path' ) ) && CORE::length( $o->param( 'path' ) ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $o->param('path') and CORE::length $o->param('path')) { } 0 0 0
Condition0%0/3
defined $o->param("path") and CORE::length $o->param("path")
!ll&&!rl&&r
000
MC/DC0%0/2
defined $o->param("path") and CORE::length $o->param("path")
defined $o->param("path") CORE::length $o->param("path")
Truth table0%0/3
A and B
A= defined $o->param("path")B= CORE::length $o->param("path")
ABresult
0X0
100
111
604 {
605 0 $c->path( $o->param( 'path' ) );
606 }
607 else
608 {
609 0 my $frag = $self->new_array( [split( /\//, $path )] );
610 # Not perfect
611 0 ▶ if( $path eq '/' || substr( $path, -1, 1 ) eq '/' )
Branch: 1 branch
BranchTrueFalseTotal
if ($path eq '/' or substr($path, -1, 1) eq '/') { } 0 0 0
Condition0%0/3
$path eq "/" or substr($path, -1, 1) eq "/"
l!l&&r!l&&!r
000
MC/DC0%0/2
$path eq "/" or substr($path, -1, 1) eq "/"
$path eq "/" substr($path, -1, 1) eq "/"
Truth table0%0/3
A or B
A= $path eq "/"B= substr($path, -1, 1) eq "/"
ABresult
1X1
011
000
612 {
613 0 $c->path( $path );
614 }
615 else
616 {
617 0 $frag->pop;
618 0 $c->path( $frag->join( '/' )->scalar );
619 }
620 }
621 0 ▶ $c->port( $port ) if( defined( $port ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $port 0 0 0
622 0 ▶ $c->http_only(1) if( $o->param( 'httponly' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $o->param("httponly") 0 0 0
623 0 ▶ $c->secure(1) if( $o->param( 'secure' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $o->param("secure") 0 0 0
624 0 ▶ $c->same_site(1) if( $o->param( 'samesite' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $o->param("samesite") 0 0 0
625  
626 0 my @old = $self->get({ name => $c->name, host => $c->domain, path => $c->path });
627 0 ▶ if( scalar( @old ) )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @old) 0 0 0
628 {
629 0 ▶ $c->created_on( $old[0]->created_on ) if( $old[0]->created_on );
Branch: 1 branch
BranchTrueFalseTotal
if $old[0]->created_on 0 0 0
630 # $self->replace( $c );
631 0 for( @old )
632 {
633 0 my $arr;
634 $arr = $self->delete( $_ ) || do
635 0 ▶ {
Condition0%0/3
$self->delete($_) || do { () }
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->delete($_) || do { () }
$self->delete($_) do { () }
Truth table0%0/3
A || B
A= $self->delete($_)B= do { () }
ABresult
1X1
011
000
636 # Error trying to remove cookie
637 };
638 }
639 }
640 0 ▶ $self->message( 3, "Adding cookie name '", $c->name, "'." ) if( $COOKIES_DEBUG );
Branch: 1 branch
BranchTrueFalseTotal
if $Cookie::Jar::COOKIES_DEBUG 0 0 0
641 0 ▶ $self->add( $c ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->add($c) or return $self->pass_error 0 0 0
642 }
643 0 return( $self );
644 }
645  
646 0 ▶sub extract_cookies { return( shift->extract( @_ ) ); }
Subroutine extract_cookies: not called CC=1 SCAR=6.9
Pod documented
647  
648 sub extract_one
649 0 ▶{
Subroutine extract_one: not called CC=25 SCAR=64.8
Pod documented
650 0 my $self = shift( @_ );
651 0 my $str = shift( @_ );
652 0 my $opts = $self->_get_args_as_hash( @_ );
653 0 ▶ $opts->{path} //= '/';
Condition0%0/2
$opts->{"path"} //= "/"
l!l
00
MC/DC0%0/1
$opts->{"path"} //= "/"
$opts->{"path"}
Truth table0%0/2
A
A= $opts->{"path"}
Aresult
11
00
654 0 ▶ return( $self->error( "No cookie data was provided." ) ) if( !length( "$str" ) );
Branch: 1 branch
BranchTrueFalseTotal
unless CORE::length "$str" 0 0 0
655  
656 0 my( $host, $root );
657 0 ▶ if( defined( $opts->{host} ) && CORE::length( $opts->{host} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opts->{"host"} and CORE::length $opts->{"host"}) 0 0 0
Condition0%0/3
defined $opts->{"host"} and CORE::length $opts->{"host"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $opts->{"host"} and CORE::length $opts->{"host"}
defined $opts->{"host"} CORE::length $opts->{"host"}
Truth table0%0/3
A and B
A= defined $opts->{"host"}B= CORE::length $opts->{"host"}
ABresult
0X0
100
111
658 {
659 0 $host = $opts->{host};
660 0 ▶ if( $self->_is_ip( $host ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_ip($host)) { } 0 0 0
661 {
662 0 $root = $host;
663 }
664 else
665 {
666 0 ▶ my $dom = Cookie::Domain->new || return( $self->pass_error( Cookie::Domain->error ) );
Condition0%0/2
'Cookie::Domain'->new || (return $self->pass_error('Cookie::Domain'->error))
l!l
00
MC/DC0%0/1
'Cookie::Domain'->new || (return $self->pass_error('Cookie::Domain'->error))
'Cookie::Domain'->new
Truth table0%0/2
A
A= 'Cookie::Domain'->new
Aresult
11
00
667 0 my $res = $dom->stat( $host );
668 0 ▶ if( !defined( $res ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $res) 0 0 0
669 {
670 0 return( $self->pass_error( $dom->error ) );
671 }
672 # Possibly empty
673 0 ▶ $root = $res ? $res->domain : '';
Branch: 1 branch
BranchTrueFalseTotal
$res ? : 0 0 0
674 }
675 }
676  
677 0 ▶ my $o = Module::Generic::HeaderValue->new_from_header( "$str" ) ||
Condition0%0/2
'Module::Generic::HeaderValue'->new_from_header("$str") || (return $self->pass_error('Module::Generic::HeaderValue'->error))
l!l
00
MC/DC0%0/1
'Module::Generic::HeaderValue'->new_from_header("$str") || (return $self->pass_error('Module::Generic::HeaderValue'->error))
'Module::Generic::HeaderValue'->new_from_header("$str")
Truth table0%0/2
A
A= 'Module::Generic::HeaderValue'->new_from_header("$str")
Aresult
11
00
678 return( $self->pass_error( Module::Generic::HeaderValue->error ) );
679 0 my( $name, $value ) = $o->value->list;
680 0 ▶ my $c = Cookie->new( name => $name, value => $value ) ||
Condition0%0/2
'Cookie'->new('name', $name, 'value', $value) || (return $self->pass_error('Cookie'->error))
l!l
00
MC/DC0%0/1
'Cookie'->new('name', $name, 'value', $value) || (return $self->pass_error('Cookie'->error))
'Cookie'->new('name', $name, 'value', $value)
Truth table0%0/2
A
A= 'Cookie'->new('name', $name, 'value', $value)
Aresult
11
00
681 return( $self->pass_error( Cookie->error ) );
682 0 ▶ if( CORE::length( $o->param( 'expires' ) ) )
Branch: 2 branches
BranchTrueFalseTotal
if (CORE::length $o->param('expires')) { } 0 0 0
elsif (CORE::length $o->param('max-age')) { } 0 0 0
683 {
684 0 my $dt = $self->_parse_timestamp( $o->param( 'expire' ) );
685 0 ▶ if( $dt )
Branch: 1 branch
BranchTrueFalseTotal
if ($dt) { } 0 0 0
686 {
687 0 $c->expires( $dt );
688 }
689 else
690 {
691 0 $c->expires( $o->param( 'expires' ) );
692 }
693 }
694 elsif( CORE::length( $o->param( 'max-age' ) ) )
695 {
696 0 $c->max_age( $o->param( 'max-age' ) );
697 }
698  
699 0 ▶ if( $o->param( 'domain' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($o->param('domain')) { } 0 0 0
700 {
701 # rfc6265, section 5.2.3:
702 # "If the first character of the attribute-value string is %x2E ("."): Let cookie-domain be the attribute-value without the leading %x2E (".") character."
703 # Ref: <https://datatracker.ietf.org/doc/html/rfc6265#section-5.2.3>
704 0 my $c_dom = $o->param( 'domain' );
705 # Remove leading dot as per rfc specifications
706 0 $c_dom =~ s/^\.//g;
707 # "Convert the cookie-domain to lower case."
708 0 $c_dom = lc( $c_dom );
709 0 $c->domain( $c_dom );
710 }
711 # "If omitted, defaults to the host of the current document URL, not including subdomains."
712 # <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie>
713 else
714 {
715 0 ▶ if( $root )
Branch: 1 branch
BranchTrueFalseTotal
if ($root) { } 0 0 0
716 {
717 0 $c->domain( $root );
718 0 $c->implicit(1);
719 }
720 else
721 {
722 }
723 }
724  
725 # rfc6265: "If the server omits the Path attribute, the user agent will use the "directory" of the request-uri's path component as the default value."
726 0 ▶ if( defined( $o->param( 'path' ) ) && CORE::length( $o->param( 'path' ) ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $o->param('path') and CORE::length $o->param('path')) { } 0 0 0
Condition0%0/3
defined $o->param("path") and CORE::length $o->param("path")
!ll&&!rl&&r
000
MC/DC0%0/2
defined $o->param("path") and CORE::length $o->param("path")
defined $o->param("path") CORE::length $o->param("path")
Truth table0%0/3
A and B
A= defined $o->param("path")B= CORE::length $o->param("path")
ABresult
0X0
100
111
727 {
728 0 $c->path( $o->param( 'path' ) );
729 }
730 else
731 {
732 0 my $frag = $self->new_array( [split( /\//, $opts->{path} )] );
733 # Not perfect
734 0 ▶ if( $opts->{path} eq '/' || substr( $opts->{path}, -1, 1 ) eq '/' )
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'path'} eq '/' or substr($opts->{'path'}, -1, 1) eq '/') { } 0 0 0
Condition0%0/3
$opts->{"path"} eq "/" or substr($opts->{"path"}, -1, 1) eq "/"
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts->{"path"} eq "/" or substr($opts->{"path"}, -1, 1) eq "/"
$opts->{"path"} eq "/" substr($opts->{"path"}, -1, 1) eq "/"
Truth table0%0/3
A or B
A= $opts->{"path"} eq "/"B= substr($opts->{"path"}, -1, 1) eq "/"
ABresult
1X1
011
000
735 {
736 0 $c->path( $opts->{path} );
737 }
738 else
739 {
740 0 $frag->pop;
741 0 $c->path( $frag->join( '/' )->scalar );
742 }
743 }
744 0 ▶ $c->port( $opts->{port} ) if( defined( $opts->{port} ) && $self->_is_integer( $opts->{port} ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $opts->{"port"} and $self->_is_integer($opts->{"port"}) 0 0 0
Condition0%0/3
defined $opts->{"port"} and $self->_is_integer($opts->{"port"})
!ll&&!rl&&r
000
MC/DC0%0/2
defined $opts->{"port"} and $self->_is_integer($opts->{"port"})
defined $opts->{"port"} $self->_is_integer($opts->{"port"})
Truth table0%0/3
A and B
A= defined $opts->{"port"}B= $self->_is_integer($opts->{"port"})
ABresult
0X0
100
111
745 0 ▶ $c->http_only(1) if( $o->param( 'httponly' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $o->param("httponly") 0 0 0
746 0 ▶ $c->secure(1) if( $o->param( 'secure' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $o->param("secure") 0 0 0
747 0 ▶ $c->same_site(1) if( $o->param( 'samesite' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $o->param("samesite") 0 0 0
748 0 return( $c );
749 }
750  
751 # From server point of view
752 sub fetch
753 0 ▶{
Subroutine fetch: not called CC=21 SCAR=61.4
Pod documented
754 0 my $self = shift( @_ );
755 0 my $opts = $self->_get_args_as_hash( @_ );
756 0 ▶ $opts->{string} //= '';
Condition0%0/2
$opts->{"string"} //= ""
l!l
00
MC/DC0%0/1
$opts->{"string"} //= ""
$opts->{"string"}
Truth table0%0/2
A
A= $opts->{"string"}
Aresult
11
00
757 0 ▶ $opts->{store} = 1 if( !CORE::exists( $opts->{store} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opts->{"store"} 0 0 0
758 0 ▶ my $host = $opts->{host} || $self->host || '';
Condition0%0/5
$opts->{'host'} || $self->host || ''
l!l
00
$opts->{"host"} or $self->host
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts->{'host'} || $self->host || ''
$opts->{"host"} $self->host
Truth table0%0/3
A or B
A= $opts->{"host"}B= $self->host
ABresult
1X1
011
000
759 0 my $cookie_header;
760 0 my $r = $self->request;
761 0 my $cookies = [];
762 0 ▶ if( $r )
Branch: 3 branches
BranchTrueFalseTotal
if ($r) { } 0 0 0
elsif ($opts->{'request'} and $self->_is_object($opts->{'request'}) and $opts->{'request'}->can('header')) { } 0 0 0
elsif (CORE::length $opts->{'string'}) { } 0 0 0
763 {
764 # try-catch
765 0 local $@;
766 eval
767 0 {
768 0 my $pool = $r->pool;
769 # my $o = APR::Request::Apache2->handle( $r->pool );
770 0 my $o = APR::Request::Apache2->handle( $r );
771 0 ▶ if( $o->jar_status =~ /^(?:Missing input data|Success)$/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($o->jar_status =~ /^(?:Missing input data|Success)$/) { } 0 0 0
772 {
773 # all cookie names in order of appearance in the Cookie request header
774 0 my @all = $o->jar;
775 0 foreach my $cookie_name ( @all )
776 {
777 0 my @values = $o->jar( $cookie_name );
778 0 foreach my $v ( @values )
779 {
780 # And of course, Apache/modperl does not uri decode the cookie value...
781 0 $v = URI::Escape::uri_unescape( $v );
782 0 my $c = $self->make( name => $cookie_name, value => $v );
783 0 push( @$cookies, $c );
784 }
785 }
786 }
787 else
788 {
789 # Malformed cookie found:
790 }
791 };
792 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
793 {
794 # An error occurred while trying to get cookies using APR::Request::Apache2, reverting to Cookie header.
795 }
796 0 $cookie_header = $r->headers_in->get( 'Cookie' );
797 }
798 ▶ elsif( $opts->{request} && $self->_is_object( $opts->{request} ) && $opts->{request}->can( 'header' ) )
Condition0%0/6
$opts->{"request"} and $self->_is_object($opts->{"request"}) and $opts->{"request"}->can("header")
!ll&&!rl&&r
000
$opts->{"request"} and $self->_is_object($opts->{"request"})
!ll&&!rl&&r
000
MC/DC0%0/3
$opts->{"request"} and $self->_is_object($opts->{"request"}) and $opts->{"request"}->can("header")
$opts->{"request"} $self->_is_object($opts->{"request"}) $opts->{"request"}->can("header")
Truth table0%0/4
A and B and C
A= $opts->{"request"}B= $self->_is_object($opts->{"request"})C= $opts->{"request"}->can("header")
ABCresult
0XX0
10X0
1100
1111
799 {
800 0 $cookie_header = $opts->{request}->header( 'Cookie' );
801 }
802 elsif( CORE::length( $opts->{string} ) )
803 {
804 0 $cookie_header = $opts->{string};
805 }
806 else
807 {
808 0 ▶ $cookie_header = $ENV{HTTP_COOKIE} // '';
Condition0%0/2
$ENV{"HTTP_COOKIE"} // ""
l!l
00
MC/DC0%0/1
$ENV{"HTTP_COOKIE"} // ""
$ENV{"HTTP_COOKIE"}
Truth table0%0/2
A
A= $ENV{"HTTP_COOKIE"}
Aresult
11
00
809 }
810 0 ▶ if( !scalar( @$cookies ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @$cookies) 0 0 0
811 {
812 0 my $ref = $self->parse( $cookie_header );
813 0 foreach my $def ( @$ref )
814 {
815 0 ▶ my $c = $self->make( name => $def->{name}, value => $def->{value} ) ||
Condition0%0/2
$self->make('name', $def->{'name'}, 'value', $def->{'value'}) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->make('name', $def->{'name'}, 'value', $def->{'value'}) || (return $self->pass_error)
$self->make('name', $def->{'name'}, 'value', $def->{'value'})
Truth table0%0/2
A
A= $self->make('name', $def->{'name'}, 'value', $def->{'value'})
Aresult
11
00
816 return( $self->pass_error );
817 0 push( @$cookies, $c );
818 }
819 }
820 # We are called in void context like $jar->fetch which means we fetch the cookies and add them to our stack internally
821 0 ▶ if( $opts->{store} )
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"store"}) 0 0 0
822 {
823 0 foreach my $c ( @$cookies )
824 {
825 0 ▶ $self->add( $c ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->add($c) or return $self->pass_error 0 0 0
826 }
827 }
828 0 return( $self->new_array( $cookies ) );
829 }
830  
831 # NOTE: the location of the cookie jar file
832 14 ▶sub file { return( shift->_set_get_file( 'file', @_ ) ); }
Subroutine file: called CC=1 SCAR=0.0
Pod documented
833  
834 sub get
835 0 ▶{
Subroutine get: not called CC=28 SCAR=67.0
Pod documented
836 0 my $self = shift( @_ );
837 # If called on the server side, $host and $path would likely be undefined
838 # my( $name, $host, $path ) = @_;
839 0 my( $name, $host, $path );
840 0 ▶ if( scalar( @_ ) == 1 && $self->_is_a( $_[0], 'Cookie' ) )
Branch: 3 branches
BranchTrueFalseTotal
if (scalar @_ == 1 and $self->_is_a($_[0], 'Cookie')) { } 0 0 0
elsif (scalar @_ == 1 and ref $_[0] eq 'HASH') { } 0 0 0
elsif (scalar @_ > 0 and scalar @_ <= 3) { } 0 0 0
Condition0%0/3
scalar @_ == 1 and $self->_is_a($_[0], "Cookie")
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @_ == 1 and $self->_is_a($_[0], "Cookie")
scalar @_ == 1 $self->_is_a($_[0], "Cookie")
Truth table0%0/3
A and B
A= scalar @_ == 1B= $self->_is_a($_[0], "Cookie")
ABresult
0X0
100
111
841 {
842 0 my $c = shift( @_ );
843 0 $name = $c->name;
844 0 $host = $c->host;
845 0 $path = $c->path;
846 }
847 ▶ elsif( scalar( @_ ) == 1 && ref( $_[0] ) eq 'HASH' )
Condition0%0/3
scalar @_ == 1 and ref $_[0] eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @_ == 1 and ref $_[0] eq "HASH"
scalar @_ == 1 ref $_[0] eq "HASH"
Truth table0%0/3
A and B
A= scalar @_ == 1B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
848 {
849 0 my $this = shift( @_ );
850 0 ( $name, $host, $path ) = @$this{qw( name host path )};
851 }
852 ▶ elsif( scalar( @_ ) > 0 && scalar( @_ ) <= 3 )
Condition0%0/3
scalar @_ > 0 and scalar @_ <= 3
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @_ > 0 and scalar @_ <= 3
scalar @_ > 0 scalar @_ <= 3
Truth table0%0/3
A and B
A= scalar @_ > 0B= scalar @_ <= 3
ABresult
0X0
100
111
853 {
854 0 ( $name, $host, $path ) = @_;
855 }
856 else
857 {
858 0 return( $self->error( "Error calling get: I was expecting either a Cookie object, or a list or hash reference of parameters." ) );
859 }
860 0 ▶ return( $self->error( "No cookie name was provided to get its object." ) ) if( !defined( $name ) || !CORE::length( $name ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name and CORE::length $name 0 0 0
Condition0%0/3
defined $name and CORE::length $name
!ll&&!rl&&r
000
MC/DC0%0/2
defined $name and CORE::length $name
defined $name CORE::length $name
Truth table0%0/3
A and B
A= defined $nameB= CORE::length $name
ABresult
0X0
100
111
861 0 ▶ $host //= $self->host || '';
Condition0%0/4
$host //= $self->host || ""
l!l
00
$self->host || ''
l!l
00
MC/DC0%0/1
$host //= $self->host || ""
$host
Truth table0%0/2
A
A= $host
Aresult
11
00
862 0 ▶ $path //= '';
Condition0%0/2
$path //= ""
l!l
00
MC/DC0%0/1
$path //= ""
$path
Truth table0%0/2
A
A= $path
Aresult
11
00
863 0 my $ref = $self->_cookies;
864 0 my $idx = $self->_index;
865 0 my $key = $self->key( $name => $host, $path );
866 # Return immediately if we found a perfect match
867 0 ▶ if( CORE::exists( $idx->{ $key } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $idx->{$key}) 0 0 0
868 {
869 0 ▶ return( wantarray() ? @{$idx->{ $key }} : $idx->{ $key }->[0] );
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
870 }
871 # If it does not exist, we check each of our cookie to see if it is a higher level cookie.
872 # For example, $host is www.example.org and our cookie key host part is example.org
873 # In this case, example.org would match, because the cookie would apply also to sub domains.
874 0 my @found = ();
875 0 foreach my $c ( @$ref )
876 {
877 0 my $c_name = $c->name;
878 0 my $c_host = $c->domain;
879 0 my $c_path = $c->path;
880  
881 0 ▶ next unless( $c_name eq $name );
Branch: 1 branch
BranchTrueFalseTotal
unless $c_name eq $name 0 0 0
882  
883  
884 0 ▶ if( !defined( $host ) || !CORE::length( $host ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $host and CORE::length $host) 0 0 0
Condition0%0/3
defined $host and CORE::length $host
!ll&&!rl&&r
000
MC/DC0%0/2
defined $host and CORE::length $host
defined $host CORE::length $host
Truth table0%0/3
A and B
A= defined $hostB= CORE::length $host
ABresult
0X0
100
111
885 {
886 0 push( @found, $c );
887 0 next;
888 }
889  
890 0 ▶ if( defined( $c_host ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $c_host and $host eq $c_host || index(reverse($host), reverse(".$c_host")) == 0) 0 0 0
Condition0%0/6
defined $c_host and $host eq $c_host || index(reverse($host), reverse(".$c_host")) == 0
!ll&&!rl&&r
000
$host eq $c_host or index(reverse($host), reverse(".$c_host")) == 0
l!l&&r!l&&!r
000
MC/DC0%0/3
defined $c_host and $host eq $c_host || index(reverse($host), reverse(".$c_host")) == 0
defined $c_host $host eq $c_host index(reverse($host), reverse(".$c_host")) == 0
Truth table0%0/4
A and B or C
A= defined $c_hostB= $host eq $c_hostC= index(reverse($host), reverse(".$c_host")) == 0
ABCresult
0XX0
1000
11X1
1011
891 ( $host eq $c_host || index( reverse( $host ), reverse( ".${c_host}" ) ) == 0 ) )
892 {
893 0 ▶ if( defined( $path ) && CORE::length( "$path" ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $path and CORE::length "$path") { } 0 0 0
Condition0%0/3
defined $path and CORE::length "$path"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $path and CORE::length "$path"
defined $path CORE::length "$path"
Truth table0%0/3
A and B
A= defined $pathB= CORE::length "$path"
ABresult
0X0
100
111
894 {
895 0 ▶ if( index( $path, $c_path ) == 0 )
Branch: 1 branch
BranchTrueFalseTotal
if (index($path, $c_path) == 0) 0 0 0
896 {
897 0 push( @found, $c );
898 }
899 }
900 else
901 {
902 0 push( @found, $c );
903 }
904 }
905 }
906  
907 0 ▶ if( scalar( @found ) )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @found) 0 0 0
908 {
909 0 ▶ return( wantarray() ? @found : $found[0] );
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
910 }
911  
912 # Ultimately, check if there is a cookie entry with just the cookie name and no host
913 # which happens for cookies repository on server side
914 0 ▶ if( CORE::exists( $idx->{ $name } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $idx->{$name}) 0 0 0
915 {
916 0 ▶ return( wantarray() ? @{$idx->{ $name }} : $idx->{ $name }->[0] );
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
917 }
918 0 return;
919 }
920  
921 sub get_by_domain
922 0 ▶{
Subroutine get_by_domain: not called CC=9 SCAR=45.0
Pod documented
923 0 my $self = shift( @_ );
924 0 my $host = shift( @_ );
925 0 my $opts = $self->_get_args_as_hash( @_ );
926 0 $opts->{with_subdomain} = 0;
927 0 ▶ $opts->{sort} = 1 if( !CORE::exists( $opts->{sort} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opts->{"sort"} 0 0 0
928 0 my $all = $self->new_array;
929 0 ▶ return( $all ) if( !defined( $host ) || !CORE::length( $host ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $host and CORE::length $host 0 0 0
Condition0%0/3
defined $host and CORE::length $host
!ll&&!rl&&r
000
MC/DC0%0/2
defined $host and CORE::length $host
defined $host CORE::length $host
Truth table0%0/3
A and B
A= defined $hostB= CORE::length $host
ABresult
0X0
100
111
930 0 $host = lc( $host );
931 0 my $ref = $self->_cookies;
932 0 foreach my $c ( @$ref )
933 {
934 0 my $dom = $c->domain;
935 0 ▶ $all->push( $c ) if( $dom eq $host || ( $opts->{with_subdomain} && $host =~ /\.$dom$/ ) );
Branch: 1 branch
BranchTrueFalseTotal
if $dom eq $host or $opts->{"with_subdomain"} and $host =~ /\.$dom$/ 0 0 0
Condition0%0/6
$dom eq $host or $opts->{"with_subdomain"} and $host =~ /\.$dom$/
l!l&&r!l&&!r
000
$opts->{"with_subdomain"} and $host =~ /\.$dom$/
!ll&&!rl&&r
000
MC/DC0%0/3
$dom eq $host or $opts->{"with_subdomain"} and $host =~ /\.$dom$/
$dom eq $host $opts->{"with_subdomain"} $host =~ /\.$dom$/
Truth table0%0/4
A or B and C
A= $dom eq $hostB= $opts->{"with_subdomain"}C= $host =~ /\.$dom$/
ABCresult
1XX1
0111
00X0
0100
936 }
937 0 my $new = [];
938 0 ▶ if( $opts->{sort} )
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'sort'}) { } 0 0 0
939 {
940 0 $new = [sort{ $a->path cmp $b->path } @$all];
941 }
942 else
943 {
944 0 $new = [sort{ $b->path cmp $a->path } @$all];
945 }
946 0 return( $self->new_array( $new ) );
947 }
948  
949 0 ▶sub host { return( shift->_set_get_scalar_as_object( 'host', @_ ) ); }
Subroutine host: not called CC=1 SCAR=6.9
Pod documented
950  
951 0 ▶sub iv { return( shift->_initialisation_vector( @_ ) ); }
Subroutine iv: not called CC=1 SCAR=6.9
Pod documented
952  
953 sub key
954 6 ▶{
Subroutine key: called CC=9 SCAR=31.1
Pod documented
955 6 my $self = shift( @_ );
956 6 my( $name, $host, $path );
957 6 ▶ if( scalar( @_ ) == 1 && $self->_is_a( $_[0], 'Cookie' ) )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ == 1 and $self->_is_a($_[0], 'Cookie')) { } 6 0 6
Condition33%1/3
scalar @_ == 1 and $self->_is_a($_[0], "Cookie")
!ll&&!rl&&r
006
MC/DC0%0/2
scalar @_ == 1 and $self->_is_a($_[0], "Cookie")
scalar @_ == 1 $self->_is_a($_[0], "Cookie")
Truth table33%1/3
A and B
A= scalar @_ == 1B= $self->_is_a($_[0], "Cookie")
ABresult
0X0
100
111
958 {
959 6 my $c = shift( @_ );
960 6 $name = $c->name;
961 6 $host = $c->domain;
962 6 $path = $c->path;
963 }
964 else
965 {
966 0 ( $name, $host, $path ) = @_;
967 0 ▶ return( $self->error( "Received cookie object '", overload::StrVal( $name // 'undef' ), "' along with cookie host '$host' and path '$path' while I was expecting cookie name, host and path. If you want to call key() with a cookie object, pass it with no other argument." ) ) if( ref( $name ) && $self->_is_a( $name, ref( $self ) ) );
Branch: 1 branch
BranchTrueFalseTotal
if ref $name and $self->_is_a($name, ref $self) 0 0 0
Condition0%0/5
ref $name and $self->_is_a($name, ref $self)
!ll&&!rl&&r
000
$name // "undef"
l!l
00
MC/DC0%0/2
ref $name and $self->_is_a($name, ref $self)
ref $name $self->_is_a($name, ref $self)
MC/DC0%0/1
$name // "undef"
$name
Truth table0%0/3
A and B
A= ref $nameB= $self->_is_a($name, ref $self)
ABresult
0X0
100
111
Truth table0%0/2
A
A= $name
Aresult
11
00
968 }
969 6 ▶ return( $self->error( "No cookie name was provided to get its key." ) ) if( !CORE::length( $name ) );
Branch: 1 branch
BranchTrueFalseTotal
unless CORE::length $name 0 6 6
970 6 ▶ return( join( ';', $host, $path, $name ) ) if( defined( $host ) && CORE::length( $host ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $host and CORE::length $host 6 0 6
Condition33%1/3
defined $host and CORE::length $host
!ll&&!rl&&r
006
MC/DC0%0/2
defined $host and CORE::length $host
defined $host CORE::length $host
Truth table33%1/3
A and B
A= defined $hostB= CORE::length $host
ABresult
0X0
100
111
971 0 return( $name );
972 }
973  
974 3 ▶sub length { return( shift->repo->length ); }
Subroutine length: called CC=1 SCAR=0.0
Pod documented
975  
976 # Load cookie data from json cookie file
977 sub load
978 0 ▶{
Subroutine load: not called CC=30 SCAR=68.4
Pod documented
979 0 my $self = shift( @_ );
980 0 ▶ my $file = shift( @_ ) || return( $self->error( "No filename was provided." ) );
Condition0%0/2
shift @_ || (return $self->error('No filename was provided.'))
l!l
00
MC/DC0%0/1
shift @_ || (return $self->error('No filename was provided.'))
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
981 0 my $opts = $self->_get_args_as_hash( @_ );
982 0 ▶ $opts->{host} //= '';
Condition0%0/2
$opts->{"host"} //= ""
l!l
00
MC/DC0%0/1
$opts->{"host"} //= ""
$opts->{"host"}
Truth table0%0/2
A
A= $opts->{"host"}
Aresult
11
00
983 0 ▶ $opts->{decrypt} //= 0;
Condition0%0/2
$opts->{"decrypt"} //= 0
l!l
00
MC/DC0%0/1
$opts->{"decrypt"} //= 0
$opts->{"decrypt"}
Truth table0%0/2
A
A= $opts->{"decrypt"}
Aresult
11
00
984 0 ▶ $opts->{algo} //= '';
Condition0%0/2
$opts->{"algo"} //= ""
l!l
00
MC/DC0%0/1
$opts->{"algo"} //= ""
$opts->{"algo"}
Truth table0%0/2
A
A= $opts->{"algo"}
Aresult
11
00
985 # Initialisation Vector for encryption
986 # Re-use it if it was previously set
987 0 ▶ $opts->{iv} //= $self->_initialisation_vector->scalar || '';
Condition0%0/4
$opts->{"iv"} //= $self->_initialisation_vector->scalar || ""
l!l
00
$self->_initialisation_vector->scalar || ''
l!l
00
MC/DC0%0/1
$opts->{"iv"} //= $self->_initialisation_vector->scalar || ""
$opts->{"iv"}
Truth table0%0/2
A
A= $opts->{"iv"}
Aresult
11
00
988 0 ▶ my $host = $opts->{host} || $self->host || '';
Condition0%0/5
$opts->{'host'} || $self->host || ''
l!l
00
$opts->{"host"} or $self->host
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts->{'host'} || $self->host || ''
$opts->{"host"} $self->host
Truth table0%0/3
A or B
A= $opts->{"host"}B= $self->host
ABresult
1X1
011
000
989 0 ▶ my $f = $self->new_file( $file ) || return( $self->pass_error );
Condition0%0/2
$self->new_file($file) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->new_file($file) || (return $self->pass_error)
$self->new_file($file)
Truth table0%0/2
A
A= $self->new_file($file)
Aresult
11
00
990 0 my $json = $f->load;
991 0 ▶ return( $self->pass_error( $f->error ) ) if( !defined( $json ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $json 0 0 0
992 # No need to go further
993 0 ▶ if( !CORE::length( $json ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (CORE::length $json) 0 0 0
994 {
995 0 return( $self );
996 }
997  
998 0 ▶ if( $opts->{decrypt} )
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"decrypt"}) 0 0 0
999 {
1000 0 my $key = $opts->{key};
1001 0 my $algo = $opts->{algo};
1002 0 ▶ return( $self->error( "Cookies file encryption was enabled, but no key was set to decrypt it." ) ) if( !defined( $key ) || !CORE::length( "$key" ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $key and CORE::length "$key" 0 0 0
Condition0%0/3
defined $key and CORE::length "$key"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $key and CORE::length "$key"
defined $key CORE::length "$key"
Truth table0%0/3
A and B
A= defined $keyB= CORE::length "$key"
ABresult
0X0
100
111
1003 0 ▶ return( $self->error( "Cookies file encryption was enabled, but no algorithm was set to decrypt it." ) ) if( !defined( $algo ) || !CORE::length( "$algo" ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $algo and CORE::length "$algo" 0 0 0
Condition0%0/3
defined $algo and CORE::length "$algo"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $algo and CORE::length "$algo"
defined $algo CORE::length "$algo"
Truth table0%0/3
A and B
A= defined $algoB= CORE::length "$algo"
ABresult
0X0
100
111
1004 0 ▶ $self->_load_class( 'Crypt::Misc', { version => CRYPTX_VERSION } ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Crypt::Misc", {"version", "0.074"}) or return $self->pass_error 0 0 0
1005 0 ▶ my $p = $self->_encrypt_objects( @$opts{qw( key algo iv )} ) || return( $self->pass_error );
Condition0%0/2
$self->_encrypt_objects(@$opts{'key', 'algo', 'iv'}) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->_encrypt_objects(@$opts{'key', 'algo', 'iv'}) || (return $self->pass_error)
$self->_encrypt_objects(@$opts{'key', 'algo', 'iv'})
Truth table0%0/2
A
A= $self->_encrypt_objects(@$opts{'key', 'algo', 'iv'})
Aresult
11
00
1006 # try-catch
1007 0 local $@;
1008 eval
1009 0 {
1010 0 my $crypt = $p->{crypt};
1011 0 my $bin = Crypt::Misc::decode_b64( "$json" );
1012 0 $json = $crypt->decrypt( "$bin", @$p{qw( key iv )} );
1013 };
1014 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1015 {
1016 0 return( $self->error( "An error occurred while trying to decrypt cookies file \"$file\": $@" ) );
1017 }
1018 }
1019  
1020 0 my $j = JSON->new->relaxed->utf8;
1021 0 my $hash;
1022 # try-catch
1023 0 local $@;
1024 $hash = eval
1025 0 {
1026 0 $j->decode( $json );
1027 };
1028 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1029 {
1030 0 return( $self->error( "Unable to decode ", CORE::length( $json ), " bytes of json data to perl: $@" ) );
1031 }
1032 0 ▶ if( ref( $hash ) ne 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $hash ne "HASH") 0 0 0
1033 {
1034 0 return( $self->error( "Data retrieved from json cookie file \"$file\" does not contain an hash as expected, but instead I got '$hash'." ) );
1035 }
1036 0 my $last_update = CORE::delete( $hash->{last_update} );
1037 0 my $repo = CORE::delete( $hash->{cookies} );
1038 0 ▶ return( $self->error( "I was expecting the JSON cookies properties to be an array, but instead I got '$repo'" ) ) if( ref( $repo ) ne 'ARRAY' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $repo ne "ARRAY" 0 0 0
1039 0 foreach my $def ( @$repo )
1040 {
1041 0 ▶ if( !CORE::exists( $def->{name} ) ||
Branch: 2 branches
BranchTrueFalseTotal
if (not exists $def->{'name'} && exists $def->{'value'}) { } 0 0 0
elsif (not defined $def->{'name'} && CORE::length $def->{'name'}) { } 0 0 0
Condition0%0/3
exists $def->{'name'} && exists $def->{'value'}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $def->{'name'} && exists $def->{'value'}
exists $def->{'name'} exists $def->{'value'}
Truth table0%0/3
A && B
A= exists $def->{'name'}B= exists $def->{'value'}
ABresult
0X0
100
111
1042 !CORE::exists( $def->{value} ) )
1043 {
1044 0 next;
1045 }
1046 ▶ elsif( !defined( $def->{name} ) || !CORE::length( $def->{name} ) )
Condition0%0/3
defined $def->{'name'} && CORE::length $def->{'name'}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $def->{'name'} && CORE::length $def->{'name'}
defined $def->{'name'} CORE::length $def->{'name'}
Truth table0%0/3
A && B
A= defined $def->{'name'}B= CORE::length $def->{'name'}
ABresult
0X0
100
111
1047 {
1048 next:
1049 0 }
1050 my $c = $self->make( $def ) || do
1051 0 ▶ {
Condition0%0/3
$self->make($def) || do { next }
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->make($def) || do { next }
$self->make($def) do { next }
Truth table0%0/3
A || B
A= $self->make($def)B= do { next }
ABresult
1X1
011
000
1052 0 next;
1053 };
1054 0 ▶ $self->add( $c ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->add($c) or return $self->pass_error 0 0 0
1055 }
1056 0 return( $self );
1057 }
1058  
1059 sub load_as_lwp
1060 0 ▶{
Subroutine load_as_lwp: not called CC=21 SCAR=61.4
Pod documented
1061 0 my $self = shift( @_ );
1062 0 ▶ my $file = shift( @_ ) || return( $self->error( "No filename was provided." ) );
Condition0%0/2
shift @_ || (return $self->error('No filename was provided.'))
l!l
00
MC/DC0%0/1
shift @_ || (return $self->error('No filename was provided.'))
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
1063 0 my $opts = $self->_get_args_as_hash( @_ );
1064 0 ▶ $opts->{decrypt} //= 0;
Condition0%0/2
$opts->{"decrypt"} //= 0
l!l
00
MC/DC0%0/1
$opts->{"decrypt"} //= 0
$opts->{"decrypt"}
Truth table0%0/2
A
A= $opts->{"decrypt"}
Aresult
11
00
1065 0 ▶ $opts->{algo} //= '';
Condition0%0/2
$opts->{"algo"} //= ""
l!l
00
MC/DC0%0/1
$opts->{"algo"} //= ""
$opts->{"algo"}
Truth table0%0/2
A
A= $opts->{"algo"}
Aresult
11
00
1066 # Initialisation Vector for encryption
1067 # Re-use it if it was previously set
1068 0 ▶ $opts->{iv} //= $self->_initialisation_vector->scalar || '';
Condition0%0/4
$opts->{"iv"} //= $self->_initialisation_vector->scalar || ""
l!l
00
$self->_initialisation_vector->scalar || ''
l!l
00
MC/DC0%0/1
$opts->{"iv"} //= $self->_initialisation_vector->scalar || ""
$opts->{"iv"}
Truth table0%0/2
A
A= $opts->{"iv"}
Aresult
11
00
1069 0 my $f = $self->new_file( $file );
1070 0 ▶ my $host = $opts->{host} || $self->host || '';
Condition0%0/5
$opts->{'host'} || $self->host || ''
l!l
00
$opts->{"host"} or $self->host
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts->{'host'} || $self->host || ''
$opts->{"host"} $self->host
Truth table0%0/3
A or B
A= $opts->{"host"}B= $self->host
ABresult
1X1
011
000
1071 0 ▶ $f->open( '<', { binmode => ( $opts->{decrypt} ? 'raw' : 'utf-8' ) }) || return( $self->pass_error( $f->error ) );
Branch: 2 branches
BranchTrueFalseTotal
$f->open("<", {"binmode", $opts->{"decrypt"} ? "raw" : "utf-8"}) or return $self->pass_error($f->error) 0 0 0
$opts->{'decrypt'} ? : 0 0 0
1072 my $code = sub
1073 0 ▶ {
Subroutine __ANON__: not called CC=2 SCAR=17.9
1074 0 ▶ if( /^Set-Cookie3:[[:blank:]\h]*(.*?)$/ )
Branch: 1 branch
BranchTrueFalseTotal
if (/^Set-Cookie3:[[:blank:]\h]*(.*?)$/) { } 0 0 0
1075 {
1076 0 my $c = $self->add( $1 );
1077 }
1078 else
1079 {
1080 # Line does not match regep.
1081 }
1082 0 };
1083  
1084 0 ▶ if( $opts->{decrypt} )
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'decrypt'}) { } 0 0 0
1085 {
1086 0 my $raw = $f->load;
1087 0 $f->close;
1088 0 my $key = $opts->{key};
1089 0 my $algo = $opts->{algo};
1090 0 ▶ return( $self->error( "Cookies file encryption was enabled, but no key was set to decrypt it." ) ) if( !defined( $key ) || !CORE::length( "$key" ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $key and CORE::length "$key" 0 0 0
Condition0%0/3
defined $key and CORE::length "$key"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $key and CORE::length "$key"
defined $key CORE::length "$key"
Truth table0%0/3
A and B
A= defined $keyB= CORE::length "$key"
ABresult
0X0
100
111
1091 0 ▶ return( $self->error( "Cookies file encryption was enabled, but no algorithm was set to decrypt it." ) ) if( !defined( $algo ) || !CORE::length( "$algo" ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $algo and CORE::length "$algo" 0 0 0
Condition0%0/3
defined $algo and CORE::length "$algo"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $algo and CORE::length "$algo"
defined $algo CORE::length "$algo"
Truth table0%0/3
A and B
A= defined $algoB= CORE::length "$algo"
ABresult
0X0
100
111
1092 0 ▶ $self->_load_class( 'Crypt::Misc', { version => CRYPTX_VERSION } ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Crypt::Misc", {"version", "0.074"}) or return $self->pass_error 0 0 0
1093 0 ▶ my $p = $self->_encrypt_objects( @$opts{qw( key algo iv )} ) || return( $self->pass_error );
Condition0%0/2
$self->_encrypt_objects(@$opts{'key', 'algo', 'iv'}) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->_encrypt_objects(@$opts{'key', 'algo', 'iv'}) || (return $self->pass_error)
$self->_encrypt_objects(@$opts{'key', 'algo', 'iv'})
Truth table0%0/2
A
A= $self->_encrypt_objects(@$opts{'key', 'algo', 'iv'})
Aresult
11
00
1094 # try-catch
1095 0 local $@;
1096 my $data = eval
1097 0 {
1098 0 my $crypt = $p->{crypt};
1099 0 my $bin = Crypt::Misc::decode_b64( "$raw" );
1100 0 $crypt->decrypt( "$bin", @$p{qw( key iv )} );
1101 };
1102 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1103 {
1104 0 return( $self->error( "An error occurred while trying to decrypt cookies file \"$file\": $@" ) );
1105 }
1106 0 my $scalar = $self->new_scalar( \$data );
1107 0 ▶ my $io = $scalar->open || return( $self->pass_error( $! ) );
Condition0%0/2
$scalar->open || (return $self->pass_error($!))
l!l
00
MC/DC0%0/1
$scalar->open || (return $self->pass_error($!))
$scalar->open
Truth table0%0/2
A
A= $scalar->open
Aresult
11
00
1108 0 ▶ $io->line( $code, chomp => 1, auto_next => 1 ) || return( $self->pass_error( $f->error ) );
Branch: 1 branch
BranchTrueFalseTotal
$io->line($code, "chomp", 1, "auto_next", 1) or return $self->pass_error($f->error) 0 0 0
1109 0 $io->close;
1110 }
1111 else
1112 {
1113 0 ▶ $f->line( $code, chomp => 1, auto_next => 1 ) || return( $self->pass_error( $f->error ) );
Branch: 1 branch
BranchTrueFalseTotal
$f->line($code, "chomp", 1, "auto_next", 1) or return $self->pass_error($f->error) 0 0 0
1114 0 $f->close;
1115 }
1116 0 return( $self );
1117 }
1118  
1119 sub load_as_mozilla
1120 2 ▶{
Subroutine load_as_mozilla: called CC=39 SCAR=54.9
Pod documented
1121 2 my $self = shift( @_ );
1122 2 ▶ my $file = shift( @_ ) || return( $self->error( "No filename was provided." ) );
Condition50%1/2
shift @_ || (return $self->error('No filename was provided.'))
l!l
20
MC/DC0%0/1
shift @_ || (return $self->error('No filename was provided.'))
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
1123 2 ▶ my $f = $self->new_file( $file ) || return( $self->pass_error );
Condition50%1/2
$self->new_file($file) || (return $self->pass_error)
l!l
20
MC/DC0%0/1
$self->new_file($file) || (return $self->pass_error)
$self->new_file($file)
Truth table50%1/2
A
A= $self->new_file($file)
Aresult
11
00
1124 2 my $opts = $self->_get_args_as_hash( @_ );
1125 2 ▶ $opts->{use_dbi} //= 0;
Condition100%2/2
$opts->{"use_dbi"} //= 0
l!l
11
MC/DC100%1/1
$opts->{"use_dbi"} //= 0
$opts->{"use_dbi"}
Truth table100%2/2
A
A= $opts->{"use_dbi"}
Aresult
11
00
1126 2 ▶ $opts->{sqlite} //= '';
Condition50%1/2
$opts->{"sqlite"} //= ""
l!l
02
MC/DC0%0/1
$opts->{"sqlite"} //= ""
$opts->{"sqlite"}
Truth table50%1/2
A
A= $opts->{"sqlite"}
Aresult
11
00
1127 # First, we copy the file, because Firefox locks it
1128 2 my $tmpfile = $self->new_tempfile( extension => 'sqlite' );
1129 2 ▶ my $sqldb = $f->copy( $tmpfile ) || return( $self->pass_error );
Condition50%1/2
$f->copy($tmpfile) || (return $self->pass_error)
l!l
20
MC/DC0%0/1
$f->copy($tmpfile) || (return $self->pass_error)
$f->copy($tmpfile)
Truth table50%1/2
A
A= $f->copy($tmpfile)
Aresult
11
00
1130 # Now, try to load DBI and DBD::SQLite
1131 2 my $dbi_error;
1132 my $sqlite_bin;
1133 2 my $cookies = [];
1134 2 ▶ my $requires_dbi = ( CORE::exists( $opts->{use_dbi} ) && defined( $opts->{use_dbi} ) && $opts->{use_dbi} ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
exists $opts->{'use_dbi'} && defined $opts->{'use_dbi'} && $opts->{'use_dbi'} ? : 1 1 2
Condition50%3/6
exists $opts->{"use_dbi"} and defined $opts->{"use_dbi"} and $opts->{"use_dbi"}
!ll&&!rl&&r
011
exists $opts->{"use_dbi"} and defined $opts->{"use_dbi"}
!ll&&!rl&&r
002
MC/DC33%1/3
exists $opts->{"use_dbi"} and defined $opts->{"use_dbi"} and $opts->{"use_dbi"}
exists $opts->{"use_dbi"} defined $opts->{"use_dbi"} $opts->{"use_dbi"}
Truth table50%2/4
A and B and C
A= exists $opts->{"use_dbi"}B= defined $opts->{"use_dbi"}C= $opts->{"use_dbi"}
ABCresult
0XX0
10X0
1100
1111
1135 2 require version;
1136 2 my $sql = <<EOT;
1137 SELECT
1138 name
1139 ,value
1140 ,host AS "domain"
1141 ,path
1142 ,expiry AS "expires"
1143 ,isSecure AS "secure"
1144 ,sameSite AS "same_site"
1145 ,isHttpOnly AS "http_only"
1146 ,CAST( ( lastAccessed / 1000000 ) AS "INTEGER" ) AS "accessed"
1147 ,CAST( ( creationTime / 1000000 ) AS "INTEGER" ) AS "created"
1148 FROM moz_cookies
1149 EOT
1150  
1151 # If the user explicitly required the use of DBI/DBD::SQLite; or
1152 # the user has not explicitly required the use of DBI/DBD::SQLite nor of sqlite3 binary
1153 2 ▶ if( $requires_dbi ||
Branch: 1 branch
BranchTrueFalseTotal
if ($requires_dbi or not $opts->{"use_dbi"} || $opts->{"sqlite"}) 2 0 2
Condition50%3/6
$requires_dbi or not $opts->{"use_dbi"} || $opts->{"sqlite"}
l!l&&r!l&&!r
110
$opts->{'use_dbi'} || $opts->{'sqlite'}
l!l&&r!l&&!r
001
MC/DC0%0/3
$requires_dbi or not $opts->{"use_dbi"} || $opts->{"sqlite"}
$requires_dbi $opts->{'use_dbi'} $opts->{'sqlite'}
Truth table50%2/4
A or not(B || C)
A= $requires_dbiB= $opts->{'use_dbi'}C= $opts->{'sqlite'}
ABCresult
1XX1
0001
01X0
0010
1154 ( !$opts->{use_dbi} && !$opts->{sqlite} ) )
1155 {
1156 2 local $@;
1157 eval
1158 2 {
1159 2 require DBI;
1160 2 require DBD::SQLite;
1161 };
1162 2 ▶ $dbi_error = $@ if( $@ );
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 2 2
1163 # User explicitly required the use of DBI/DBD::SQLite, but it failed, so we return an error
1164 2 ▶ if( defined( $dbi_error ) && exists( $opts->{use_dbi} ) && defined( $opts->{use_dbi} ) && $opts->{use_dbi} )
Branch: 2 branches
BranchTrueFalseTotal
if (defined $dbi_error and exists $opts->{'use_dbi'} and defined $opts->{'use_dbi'} and $opts->{'use_dbi'}) { } 0 2 2
elsif (not defined $dbi_error) { } 2 0 2
Condition33%3/9
defined $dbi_error and exists $opts->{"use_dbi"} and defined $opts->{"use_dbi"} and $opts->{"use_dbi"}
!ll&&!rl&&r
200
defined $dbi_error and exists $opts->{"use_dbi"} and defined $opts->{"use_dbi"}
!ll&&!rl&&r
200
defined $dbi_error and exists $opts->{"use_dbi"}
!ll&&!rl&&r
200
MC/DC0%0/4
defined $dbi_error and exists $opts->{"use_dbi"} and defined $opts->{"use_dbi"} and $opts->{"use_dbi"}
defined $dbi_error exists $opts->{"use_dbi"} defined $opts->{"use_dbi"} $opts->{"use_dbi"}
Truth table20%1/5
A and B and C and D
A= defined $dbi_errorB= exists $opts->{"use_dbi"}C= defined $opts->{"use_dbi"}D= $opts->{"use_dbi"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1165 {
1166 0 return( $self->error( "Unable to load either DBI or DBD::SQLite: $@" ) );
1167 }
1168 elsif( !defined( $dbi_error ) )
1169 {
1170 # As of Firefox 106.0.5 (2022-11-06), the cookie table structure is:
1171 # CREATE TABLE moz_cookies(
1172 # id INTEGER PRIMARY KEY,
1173 # originAttributes TEXT NOT NULL DEFAULT '',
1174 # name TEXT,
1175 # value TEXT,
1176 # host TEXT,
1177 # path TEXT,
1178 # expiry INTEGER,
1179 # lastAccessed INTEGER,
1180 # creationTime INTEGER,
1181 # isSecure INTEGER,
1182 # isHttpOnly INTEGER,
1183 # inBrowserElement INTEGER DEFAULT 0,
1184 # sameSite INTEGER DEFAULT 0,
1185 # rawSameSite INTEGER DEFAULT 0,
1186 # schemeMap INTEGER DEFAULT 0,
1187 # CONSTRAINT moz_uniqueid UNIQUE(name, host, path, originAttributes)
1188 # );
1189 # 'expiry' is a unix timestamp
1190 # 'lastAccessed' and 'creationTime' are in microseconds
1191 # try-catch
1192 2 local $@;
1193 eval
1194 2 {
1195 2 ▶ my $dbh = DBI->connect( "dbi:SQLite:dbname=${sqldb}", '', '', { RaiseError => 1 } ) ||
Condition50%1/2
'DBI'->connect("dbi:SQLite:dbname=$sqldb", '', '', {'RaiseError', 1}) || die("Unable to connect to SQLite database file ${sqldb}: ", $DBI::errstr)
l!l
20
MC/DC0%0/1
'DBI'->connect("dbi:SQLite:dbname=$sqldb", '', '', {'RaiseError', 1}) || die("Unable to connect to SQLite database file ${sqldb}: ", $DBI::errstr)
'DBI'->connect("dbi:SQLite:dbname=$sqldb", '', '', {'RaiseError', 1})
Truth table50%1/2
A
A= 'DBI'->connect("dbi:SQLite:dbname=$sqldb", '', '', {'RaiseError', 1})
Aresult
11
00
1196 die( "Unable to connect to SQLite database file ${sqldb}: ", $DBI::errstr );
1197 2 ▶ my $tbl_check = $dbh->table_info( undef, undef, 'moz_cookies', 'TABLE' ) ||
Condition50%1/2
$dbh->table_info(undef, undef, 'moz_cookies', 'TABLE') || die("Error checking for existence of table 'moz_cookies' in SQLite database file ${sqldb}: ", $dbh->errstr)
l!l
20
MC/DC0%0/1
$dbh->table_info(undef, undef, 'moz_cookies', 'TABLE') || die("Error checking for existence of table 'moz_cookies' in SQLite database file ${sqldb}: ", $dbh->errstr)
$dbh->table_info(undef, undef, 'moz_cookies', 'TABLE')
Truth table50%1/2
A
A= $dbh->table_info(undef, undef, 'moz_cookies', 'TABLE')
Aresult
11
00
1198 die( "Error checking for existence of table 'moz_cookies' in SQLite database file ${sqldb}: ", $dbh->errstr );
1199 2 ▶ $tbl_check->execute || die( "Error executing query to check existence of table 'moz_cookies': ", $tbl_check->errstr );
Branch: 1 branch
BranchTrueFalseTotal
$tbl_check->execute or die "Error executing query to check existence of table 'moz_cookies': ", $tbl_check->errstr 2 0 2
1200 2 my $found = $tbl_check->fetchrow;
1201 2 $tbl_check->finish;
1202 2 ▶ if( !$found )
Branch: 1 branch
BranchTrueFalseTotal
unless ($found) 0 2 2
1203 {
1204 0 die( "No table 'moz_cookies' found in SQLite database ${sqldb}" );
1205 }
1206 2 ▶ my $sth = $dbh->prepare( $sql ) ||
Condition50%1/2
$dbh->prepare($sql) || die("Error preparing the sql query to get all mozilla cookies from database ${sqldb}: ", $dbh->errstr, "\nSQL query was: $sql")
l!l
20
MC/DC0%0/1
$dbh->prepare($sql) || die("Error preparing the sql query to get all mozilla cookies from database ${sqldb}: ", $dbh->errstr, "\nSQL query was: $sql")
$dbh->prepare($sql)
Truth table50%1/2
A
A= $dbh->prepare($sql)
Aresult
11
00
1207 die( "Error preparing the sql query to get all mozilla cookies from database ${sqldb}: ", $dbh->errstr, "\nSQL query was: ${sql}" );
1208 2 ▶ $sth->execute() ||
Branch: 1 branch
BranchTrueFalseTotal
$sth->execute or die "Error executing sql query to get all mozilla cookies from database ${sqldb}: ", $sth->errstr, "\nSQL query was: $sql" 2 0 2
1209 die( "Error executing sql query to get all mozilla cookies from database ${sqldb}: ", $sth->errstr, "\nSQL query was: ${sql}" );
1210 2 $cookies = $sth->fetchall_arrayref;
1211 2 $sth->finish;
1212 2 $dbh->disconnect;
1213 2 $sqldb->remove;
1214 };
1215 2 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 2 2
1216 {
1217 0 ▶ if( $requires_dbi )
Branch: 1 branch
BranchTrueFalseTotal
if ($requires_dbi) { } 0 0 0
1218 {
1219 0 return( $self->error( "Error trying to get mozilla cookies from SQLite database ${sqldb} using DBI: $@" ) );
1220 }
1221 else
1222 {
1223 0 ▶ warn( "Non fatal error occurred while trying to get mozilla cookies from SQLite database ${sqldb} using DBI: $@\n" ) if( $self->_warnings_is_enabled );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_warnings_is_enabled 0 0 0
1224 }
1225 }
1226 }
1227 }
1228  
1229 # If there is no cookies found yet; and
1230 # the user did not require exclusively the use of DBI, but required the use of sqlite3 binary
1231 # the user did not require the use of DBI nor the use of sqlite3 binary
1232 2 ▶ if( !scalar( @$cookies ) && !$requires_dbi )
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @$cookies or $requires_dbi) 0 2 2
Condition33%1/3
scalar @$cookies or $requires_dbi
l!l&&r!l&&!r
200
MC/DC0%0/2
scalar @$cookies or $requires_dbi
scalar @$cookies $requires_dbi
Truth table33%1/3
A or B
A= scalar @$cookiesB= $requires_dbi
ABresult
1X1
011
000
1233 {
1234 # If the user required specific sqlite3 binary
1235 0 ▶ if( exists( $opts->{sqlite} ) && defined( $opts->{sqlite} ) && CORE::length( $opts->{sqlite} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts->{'sqlite'} and defined $opts->{'sqlite'} and CORE::length $opts->{'sqlite'}) { } 0 0 0
Condition0%0/6
exists $opts->{"sqlite"} and defined $opts->{"sqlite"} and CORE::length $opts->{"sqlite"}
!ll&&!rl&&r
000
exists $opts->{"sqlite"} and defined $opts->{"sqlite"}
!ll&&!rl&&r
000
MC/DC0%0/3
exists $opts->{"sqlite"} and defined $opts->{"sqlite"} and CORE::length $opts->{"sqlite"}
exists $opts->{"sqlite"} defined $opts->{"sqlite"} CORE::length $opts->{"sqlite"}
Truth table0%0/4
A and B and C
A= exists $opts->{"sqlite"}B= defined $opts->{"sqlite"}C= CORE::length $opts->{"sqlite"}
ABCresult
0XX0
10X0
1100
1111
1236 {
1237 0 ▶ if( !-e( $opts->{sqlite} ) )
Branch: 2 branches
BranchTrueFalseTotal
if (not -e $opts->{'sqlite'}) { } 0 0 0
elsif (not -x $opts->{'sqlite'}) { } 0 0 0
1238 {
1239 0 return( $self->error( "sqlite3 binary path provided \"$opts->{sqlite}\" does not exist." ) );
1240 }
1241 elsif( !-x( $opts->{sqlite} ) )
1242 {
1243 0 return( $self->error( "sqlite3 binary path provided \"$opts->{sqlite}\" is not executable by user id $>" ) );
1244 }
1245 0 $sqlite_bin = $opts->{sqlite};
1246 }
1247 else
1248 {
1249 0 require File::Which;
1250 0 my $bin = File::Which::which( 'sqlite3' );
1251 0 ▶ if( !defined( $bin ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $bin) 0 0 0
1252 {
1253 0 return( $self->error( "DBI and/or DBD::SQLite modules are not installed and I could not find thr sqlite3 binary anywhere." ) );
1254 }
1255 0 $sqlite_bin = $bin;
1256 }
1257  
1258 0 $sql =~ s/\n/ /gs;
1259 0 ▶ open( my $fh, '-|', $sqlite_bin, '-noheader', '-separator', '|', "${sqldb}", $sql ) ||
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "-|", $sqlite_bin, "-noheader", "-separator", "|", "$sqldb", $sql or return $self->error("Failed to execute sqlite3 binary with sql query to get all mozilla cookies from database ${sqldb}: $!") 0 0 0
1260 return( $self->error( "Failed to execute sqlite3 binary with sql query to get all mozilla cookies from database ${sqldb}: $!" ) );
1261 # $cookies = [map{ [split( /\|/, $_ )] } <$fh>];
1262 0 ▶ while( defined( $_ = <$fh> ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 0 0 0
1263 {
1264 0 chomp;
1265 0 push( @$cookies, [split( /\|/, $_ )] );
1266 }
1267 0 close( $fh );
1268 }
1269  
1270 2 foreach my $ref ( @$cookies )
1271 {
1272 4 my( $name, $value, $domain, $path, $expires, $secure, $same_site, $http_only, $accessed, $created ) = @$ref;
1273 4 ▶ $self->add({
Branch: 1 branch
BranchTrueFalseTotal
$self->add({"name", $name, "value", $value, "domain", $domain, "path", $path, "expires", $expires, "secure", $secure, "http_only", $http_only, "same_site", $same_site, "accessed_on", $accessed, "created_on", $created}) or return $self->pass_error 4 0 4
1274 name => $name,
1275 value => $value,
1276 domain => $domain,
1277 path => $path,
1278 expires => $expires,
1279 secure => $secure,
1280 http_only => $http_only,
1281 same_site => $same_site,
1282 accessed_on => $accessed,
1283 created_on => $created,
1284 }) || return( $self->pass_error );
1285 }
1286 2 return( $self );
1287 }
1288  
1289 sub load_as_netscape
1290 0 ▶{
Subroutine load_as_netscape: not called CC=7 SCAR=40.3
Pod documented
1291 0 my $self = shift( @_ );
1292 0 ▶ my $file = shift( @_ ) || return( $self->error( "No filename was provided." ) );
Condition0%0/2
shift @_ || (return $self->error('No filename was provided.'))
l!l
00
MC/DC0%0/1
shift @_ || (return $self->error('No filename was provided.'))
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
1293 0 ▶ my $f = $self->new_file( $file ) || return( $self->pass_error );
Condition0%0/2
$self->new_file($file) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->new_file($file) || (return $self->pass_error)
$self->new_file($file)
Truth table0%0/2
A
A= $self->new_file($file)
Aresult
11
00
1294 0 my $opts = $self->_get_args_as_hash( @_ );
1295 0 ▶ my $host = $opts->{host} || $self->host || '';
Condition0%0/5
$opts->{'host'} || $self->host || ''
l!l
00
$opts->{"host"} or $self->host
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts->{'host'} || $self->host || ''
$opts->{"host"} $self->host
Truth table0%0/3
A or B
A= $opts->{"host"}B= $self->host
ABresult
1X1
011
000
1296 0 ▶ $f->open || return( $self->pass_error( $f->error ) );
Branch: 1 branch
BranchTrueFalseTotal
$f->open or return $self->pass_error($f->error) 0 0 0
1297 $f->line(sub
1298 0 ▶ {
Subroutine __ANON__: not called CC=3 SCAR=24.8
1299 0 my( $domain, $sub_too, $path, $secure, $expires, $name, $value ) = split( /\t/, $_ );
1300 0 ▶ $secure = ( lc( $secure ) eq 'true' ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
lc $secure eq 'true' ? : 0 0 0
1301 # rfc6265 makes obsolete domains prepended with a dot.
1302 0 ▶ $domain = substr( $domain, 1 ) if( substr( $domain, 1, 1 ) eq '.' );
Branch: 1 branch
BranchTrueFalseTotal
if substr($domain, 1, 1) eq "." 0 0 0
1303 0 $self->add({
1304 name => $name,
1305 value => $value,
1306 domain => $domain,
1307 path => $path,
1308 expires => $expires,
1309 secure => $secure,
1310 });
1311 0 ▶ }, chomp => 1, auto_next => 1 ) || return( $self->pass_error( $f->error ) );
Branch: 1 branch
BranchTrueFalseTotal
$f->line(sub { my($domain, $sub_too, $path, $secure, $expires, $name, $value) = split(/\t/, $_, 8); $secure = lc $secure eq "true" ? 1 : 0; $domain = substr($domain, 1) if substr($domain, 1, 1) eq "."; $self->add({"name", $name, "value", $value, "domain", $domain, "path", $path, "expires", $expires, "secure", $secure}); } , "chomp", 1, "auto_next", 1) or return $self->pass_error($f->error) 0 0 0
1312 0 return( $self );
1313 }
1314  
1315 sub make
1316 7 ▶{
Subroutine make: called CC=4 SCAR=14.1
Pod documented
1317 7 my $self = shift( @_ );
1318 7 my $opts = $self->_get_args_as_hash( @_ );
1319 8 ▶ no overloading;
Subroutine BEGIN: called CC=1 SCAR=0.0
1320 7 ▶ return( $self->error( "Cookie name was not provided." ) ) if( !$opts->{name} );
Branch: 1 branch
BranchTrueFalseTotal
unless $opts->{"name"} 0 7 7
1321 7 $opts->{debug} = $self->debug;
1322 7 my $c = Cookie->new( debug => $self->debug );
1323 7 ▶ return( $self->pass_error( Cookie->error ) ) if( !defined( $c ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $c 0 7 7
1324 7 ▶ $c->apply( $opts ) || return( $self->pass_error( $c->error ) );
Branch: 1 branch
BranchTrueFalseTotal
$c->apply($opts) or return $self->pass_error($c->error) 7 0 7
1325 7 return( $c );
1326 }
1327  
1328 sub merge
1329 0 ▶{
Subroutine merge: not called CC=10 SCAR=47.0
Pod documented
1330 0 my $self = shift( @_ );
1331 0 ▶ my $jar = shift( @_ ) || return( $self->error( "No Cookie::Jar object was provided to merge." ) );
Condition0%0/2
shift @_ || (return $self->error('No Cookie::Jar object was provided to merge.'))
l!l
00
MC/DC0%0/1
shift @_ || (return $self->error('No Cookie::Jar object was provided to merge.'))
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
1332 0 my $opts = $self->_get_args_as_hash( @_ );
1333 0 ▶ return( $self->error( "Cookie::Jar object provided (", overload::StrVal( $jar // 'undef' ), ") is not a Cookie::Jar object." ) ) if( !$self->_is_a( $jar, 'Cookie::Jar' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_a($jar, "Cookie::Jar") 0 0 0
Condition0%0/2
$jar // "undef"
l!l
00
MC/DC0%0/1
$jar // "undef"
$jar
Truth table0%0/2
A
A= $jar
Aresult
11
00
1334 # We require the do method on purpose, because the scan method is from the old HTTP::Cookies api which does not send an object, but a list of cookie property value
1335 0 ▶ return( $self->error( "Cookie::Jar object provided does not have a method \"do\"." ) ) if( !$jar->can( 'do' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $jar->can("do") 0 0 0
1336 0 ▶ $opts->{overwrite} //= 0;
Condition0%0/2
$opts->{"overwrite"} //= 0
l!l
00
MC/DC0%0/1
$opts->{"overwrite"} //= 0
$opts->{"overwrite"}
Truth table0%0/2
A
A= $opts->{"overwrite"}
Aresult
11
00
1337 0 ▶ $opts->{host} //= $self->host || '';
Condition0%0/4
$opts->{"host"} //= $self->host || ""
l!l
00
$self->host || ''
l!l
00
MC/DC0%0/1
$opts->{"host"} //= $self->host || ""
$opts->{"host"}
Truth table0%0/2
A
A= $opts->{"host"}
Aresult
11
00
1338 0 ▶ $opts->{die} //= 0;
Condition0%0/2
$opts->{"die"} //= 0
l!l
00
MC/DC0%0/1
$opts->{"die"} //= 0
$opts->{"die"}
Truth table0%0/2
A
A= $opts->{"die"}
Aresult
11
00
1339 0 my $n = 0;
1340 0 my $error;
1341 $jar->do(sub
1342 0 ▶ {
Subroutine __ANON__: not called CC=20 SCAR=60.4
1343 # Skip the rest if we already found an error
1344 0 ▶ return if( defined( $error ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $error 0 0 0
1345 0 my $c = shift( @_ );
1346 0 ▶ if( $self->_is_object( $c ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_object($c)) 0 0 0
1347 {
1348 0 ▶ if( $self->_is_a( $c, 'Cookie' ) )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_is_a($c, 'Cookie')) { } 0 0 0
elsif ($c->can('name') and $c->can('value') and $c->can('domain') and $c->can('path') and $c->can('expires') and $c->can('max_age') and $c->can('port') and $c->can('secure') and $c->can('same_site') and $c->can('http_only')) { } 0 0 0
1349 {
1350 0 ▶ if( $opts->{overwrite} )
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'overwrite'}) { } 0 0 0
1351 {
1352 0 $self->replace( $c );
1353 }
1354 else
1355 {
1356 0 $self->add( $c );
1357 }
1358 0 $n++;
1359 }
1360 ▶ elsif( $c->can( 'name' ) &&
Condition0%0/27
$c->can("name") and $c->can("value") and $c->can("domain") and $c->can("path") and $c->can("expires") and $c->can("max_age") and $c->can("port") and $c->can("secure") and $c->can("same_site") and $c->can("http_only")
!ll&&!rl&&r
000
$c->can("name") and $c->can("value") and $c->can("domain") and $c->can("path") and $c->can("expires") and $c->can("max_age") and $c->can("port") and $c->can("secure") and $c->can("same_site")
!ll&&!rl&&r
000
$c->can("name") and $c->can("value") and $c->can("domain") and $c->can("path") and $c->can("expires") and $c->can("max_age") and $c->can("port") and $c->can("secure")
!ll&&!rl&&r
000
$c->can("name") and $c->can("value") and $c->can("domain") and $c->can("path") and $c->can("expires") and $c->can("max_age") and $c->can("port")
!ll&&!rl&&r
000
$c->can("name") and $c->can("value") and $c->can("domain") and $c->can("path") and $c->can("expires") and $c->can("max_age")
!ll&&!rl&&r
000
$c->can("name") and $c->can("value") and $c->can("domain") and $c->can("path") and $c->can("expires")
!ll&&!rl&&r
000
$c->can("name") and $c->can("value") and $c->can("domain") and $c->can("path")
!ll&&!rl&&r
000
$c->can("name") and $c->can("value") and $c->can("domain")
!ll&&!rl&&r
000
$c->can("name") and $c->can("value")
!ll&&!rl&&r
000
MC/DC0%0/10
$c->can("name") and $c->can("value") and $c->can("domain") and $c->can("path") and $c->can("expires") and $c->can("max_age") and $c->can("port") and $c->can("secure") and $c->can("same_site") and $c->can("http_only")
$c->can("name") $c->can("value") $c->can("domain") $c->can("path") $c->can("expires") $c->can("max_age") $c->can("port") $c->can("secure") $c->can("same_site") $c->can("http_only")
Truth table0%0/11
A and B and C and D and E and F and G and H and I and J
A= $c->can("name")B= $c->can("value")C= $c->can("domain")D= $c->can("path")E= $c->can("expires")F= $c->can("max_age")G= $c->can("port")H= $c->can("secure")I= $c->can("same_site")J= $c->can("http_only")
ABCDEFGHIJresult
0XXXXXXXXX0
10XXXXXXXX0
110XXXXXXX0
1110XXXXXX0
11110XXXXX0
111110XXXX0
1111110XXX0
11111110XX0
111111110X0
11111111100
11111111111
1361 $c->can( 'value' ) &&
1362 $c->can( 'domain' ) &&
1363 $c->can( 'path' ) &&
1364 $c->can( 'expires' ) &&
1365 $c->can( 'max_age' ) &&
1366 $c->can( 'port' ) &&
1367 $c->can( 'secure' ) &&
1368 $c->can( 'same_site' ) &&
1369 $c->can( 'http_only' ) )
1370 {
1371 0 my $new = $jar->make(
1372 name => $c->name,
1373 value => $c->value,
1374 domain => $c->domain,
1375 path => $c->path,
1376 expires => $c->expires,
1377 max_age => $c->max_age,
1378 http_only => $c->http_only,
1379 same_site => $c->same_site,
1380 secure => $c->secure,
1381 );
1382 0 ▶ if( !defined( $new ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $new) { } 0 0 0
1383 {
1384 0 $error = $jar->error;
1385 0 ▶ die( $error ) if( $opts->{die} );
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"die"} 0 0 0
1386 }
1387 else
1388 {
1389 0 ▶ if( $opts->{overwrite} )
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'overwrite'}) { } 0 0 0
1390 {
1391 0 $self->replace( $new );
1392 }
1393 else
1394 {
1395 0 $self->add( $new );
1396 }
1397 0 $n++;
1398 }
1399 }
1400 else
1401 {
1402 0 ▶ $error = "Cookie object received (" . overload::StrVal( $c // 'undef' ) . ") is not a Cookie object and does not support the methods name, value, domain, path, port, expires, max_age, secure, same_site and http_only";
Condition0%0/2
$c // "undef"
l!l
00
MC/DC0%0/1
$c // "undef"
$c
Truth table0%0/2
A
A= $c
Aresult
11
00
1403 0 ▶ die( $error ) if( $opts->{die} );
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"die"} 0 0 0
1404 }
1405 }
1406 0 });
1407 0 ▶ return( $self->error( $error ) ) if( defined( $error ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $error 0 0 0
1408 0 return( $self );
1409 }
1410  
1411 # Swell:
1412 # "if the Cookie header field contains two cookies with the same name (e.g., that were set with different Path or Domain attributes), servers SHOULD NOT rely upon the order in which these cookies appear in the header field."
1413 # <https://datatracker.ietf.org/doc/html/rfc6265#section-4.2.2>
1414 sub parse
1415 22 ▶{
Subroutine parse: called CC=5 SCAR=16.1
Pod documented
1416 22 my $self = shift( @_ );
1417 22 my $raw = shift( @_ );
1418 22 my $ref = $self->new_array;
1419 22 ▶ return( $ref ) unless( defined( $raw ) && CORE::length( $raw ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $raw and CORE::length $raw 2 20 22
Condition100%3/3
defined $raw and CORE::length $raw
!ll&&!rl&&r
1120
MC/DC100%2/2
defined $raw and CORE::length $raw
defined $raw CORE::length $raw
Truth table100%3/3
A and B
A= defined $rawB= CORE::length $raw
ABresult
0X0
100
111
1420 20 my @pairs = grep( /=/, split( /; ?/, $raw ) );
1421 20 foreach my $pair ( @pairs )
1422 {
1423 # Remove leading and trailing whitespaces
1424 57 $pair =~ s/^[[:blank:]\h]+|[[:blank:]\h]+$//g;
1425 57 my( $k, $v ) = split( '=', $pair, 2 );
1426 57 $k = URI::Escape::uri_unescape( $k );
1427 57 ▶ $v = '' unless( defined( $v ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 57 57
1428 57 $v =~ s/\A"(.*)"\z/$1/;
1429 57 $v = URI::Escape::uri_unescape( $v );
1430 57 $ref->push( { name => $k, value => $v } );
1431 }
1432 20 return( $ref );
1433 }
1434  
1435 sub purge
1436 0 ▶{
Subroutine purge: not called CC=4 SCAR=30.0
Pod documented
1437 0 my $self = shift( @_ );
1438 0 my $ref = $self->_cookies;
1439 0 my $removed = $self->new_array;
1440 0 ▶ for( my $i = 0; $i < scalar( @$ref ); $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @$ref) 0 0 0
1441 {
1442 0 my $c = $ref->[$i];
1443 0 ▶ if( $c->is_expired )
Branch: 1 branch
BranchTrueFalseTotal
if ($c->is_expired) 0 0 0
1444 {
1445 0 ▶ $self->delete( $c ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->delete($c) or return $self->pass_error 0 0 0
1446 0 $removed->push( $c );
1447 }
1448 }
1449 0 return( $removed );
1450 }
1451  
1452 3 ▶sub repo { return( shift->_set_get_array_as_object( '_cookies', @_ ) ); }
Subroutine repo: called CC=1 SCAR=0.0
Pod documented
1453  
1454 sub replace
1455 0 ▶{
Subroutine replace: not called CC=19 SCAR=59.4
Pod documented
1456 0 my $self = shift( @_ );
1457 0 my( $c, $old ) = @_;
1458 0 my $idx = $self->_index;
1459 0 my $ref = $self->_cookies;
1460 0 ▶ return( $self->error( "No cookie object was provided." ) ) if( !defined( $c ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $c 0 0 0
1461 0 ▶ return( $self->error( "Cookie object provided is not a Cookie object." ) ) if( !$self->_is_a( $c, 'Cookie' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_a($c, "Cookie") 0 0 0
1462 0 my $replaced = $self->new_array;
1463 0 ▶ if( defined( $old ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $old) { } 0 0 0
1464 {
1465 0 ▶ return( $self->error( "Old cookie object to be replaced is not a Cookie object." ) ) if( !$self->_is_a( $old, 'Cookie' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_a($old, "Cookie") 0 0 0
1466 0 ▶ if( $c->name ne $old->name ||
Branch: 1 branch
BranchTrueFalseTotal
if ($c->name ne $old->name or $c->domain ne $old->domain or $c->path ne $old->path) 0 0 0
Condition0%0/6
$c->name ne $old->name or $c->domain ne $old->domain or $c->path ne $old->path
l!l&&r!l&&!r
000
$c->name ne $old->name or $c->domain ne $old->domain
l!l&&r!l&&!r
000
MC/DC0%0/3
$c->name ne $old->name or $c->domain ne $old->domain or $c->path ne $old->path
$c->name ne $old->name $c->domain ne $old->domain $c->path ne $old->path
Truth table0%0/4
A or B or C
A= $c->name ne $old->nameB= $c->domain ne $old->domainC= $c->path ne $old->path
ABCresult
1XX1
01X1
0011
0000
1467 $c->domain ne $old->domain ||
1468 $c->path ne $old->path )
1469 {
1470 0 return( $self->error( "New cookie name '", $c->name, "' with host '", $c->domain, "' and path '", $c->path, "' does not match old cookie name '", $old->name, "' with host '", $old->host, "' and path '", $old->path, "'" ) );
1471 }
1472 0 ▶ my $key = $self->key( $old ) || return( $self->pass_error );
Condition0%0/2
$self->key($old) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->key($old) || (return $self->pass_error)
$self->key($old)
Truth table0%0/2
A
A= $self->key($old)
Aresult
11
00
1473 0 my $addr = Scalar::Util::refaddr( $old );
1474 0 ▶ if( CORE::exists( $idx->{ $key } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $idx->{$key}) 0 0 0
1475 {
1476 0 ▶ for( my $i = 0; $i < scalar( @{$idx->{ $key }} ); $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @{$idx->{$key};}) 0 0 0
1477 {
1478 0 ▶ if( Scalar::Util::refaddr( $idx->{ $key }->[$i] ) eq $addr )
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::refaddr($idx->{$key}[$i]) eq $addr) 0 0 0
1479 {
1480 0 $idx->{ $key }->[$i] = $c;
1481 0 last;
1482 }
1483 }
1484 }
1485 0 ▶ for( my $i = 0; $i < scalar( @$ref ); $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @$ref) 0 0 0
1486 {
1487 0 ▶ if( Scalar::Util::refaddr( $ref->[$i] ) eq $addr )
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::refaddr($ref->[$i]) eq $addr) 0 0 0
1488 {
1489 0 $replaced->push( $ref->[$i] );
1490 0 $ref->[$i] = $c;
1491 0 last;
1492 }
1493 }
1494 }
1495 else
1496 {
1497 0 ▶ my $key = $self->key( $c ) || return( $self->pass_error );
Condition0%0/2
$self->key($c) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->key($c) || (return $self->pass_error)
$self->key($c)
Truth table0%0/2
A
A= $self->key($c)
Aresult
11
00
1498 0 ▶ $replaced->push( CORE::exists( $idx->{ $key } ) ? @{$idx->{ $key }} : () );
Branch: 1 branch
BranchTrueFalseTotal
exists $idx->{$key} ? : 0 0 0
1499 0 foreach my $old ( @$replaced )
1500 {
1501 0 my $addr = Scalar::Util::refaddr( $old );
1502 0 ▶ for( my $j = 0; $j < scalar( @$ref ); $j++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($j < scalar @$ref) 0 0 0
1503 {
1504 0 ▶ if( Scalar::Util::refaddr( $ref->[$j] ) eq $addr )
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::refaddr($ref->[$j]) eq $addr) 0 0 0
1505 {
1506 0 CORE::splice( @$ref, $j, 1 );
1507 0 $j--;
1508 0 last;
1509 }
1510 }
1511 }
1512 0 $idx->{ $key } = [ $c ];
1513 }
1514 0 return( $replaced );
1515 }
1516  
1517 1 ▶sub request { return( shift->_set_get_object_without_init( 'request', 'Apache2::RequestRec', @_ ) ); }
Subroutine request: called CC=1 SCAR=0.0
Pod documented
1518  
1519 sub save
1520 0 ▶{
Subroutine save: not called CC=18 SCAR=58.3
Pod documented
1521 0 my $self = shift( @_ );
1522 0 ▶ my $file = shift( @_ ) || return( $self->error( "No filename was provided." ) );
Condition0%0/2
shift @_ || (return $self->error('No filename was provided.'))
l!l
00
MC/DC0%0/1
shift @_ || (return $self->error('No filename was provided.'))
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
1523 0 my $opts = $self->_get_args_as_hash( @_ );
1524 0 ▶ $opts->{encrypt} //= 0;
Condition0%0/2
$opts->{"encrypt"} //= 0
l!l
00
MC/DC0%0/1
$opts->{"encrypt"} //= 0
$opts->{"encrypt"}
Truth table0%0/2
A
A= $opts->{"encrypt"}
Aresult
11
00
1525 0 ▶ $opts->{algo} //= '';
Condition0%0/2
$opts->{"algo"} //= ""
l!l
00
MC/DC0%0/1
$opts->{"algo"} //= ""
$opts->{"algo"}
Truth table0%0/2
A
A= $opts->{"algo"}
Aresult
11
00
1526 # Initialisation Vector for encryption
1527 # Re-use it if it was previously set
1528 0 ▶ $opts->{iv} //= $self->_initialisation_vector->scalar || '';
Condition0%0/4
$opts->{"iv"} //= $self->_initialisation_vector->scalar || ""
l!l
00
$self->_initialisation_vector->scalar || ''
l!l
00
MC/DC0%0/1
$opts->{"iv"} //= $self->_initialisation_vector->scalar || ""
$opts->{"iv"}
Truth table0%0/2
A
A= $opts->{"iv"}
Aresult
11
00
1529 0 ▶ $opts->{format} //= '';
Condition0%0/2
$opts->{"format"} //= ""
l!l
00
MC/DC0%0/1
$opts->{"format"} //= ""
$opts->{"format"}
Truth table0%0/2
A
A= $opts->{"format"}
Aresult
11
00
1530 0 ▶ return( $self->save_as_lwp( $opts ) ) if( $opts->{format} eq 'lwp' );
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"format"} eq "lwp" 0 0 0
1531 0 my $all = [];
1532 0 my $ref = $self->_cookies;
1533 0 foreach my $c ( @$ref )
1534 {
1535 0 push( @$all, $c->as_hash );
1536 }
1537 0 my $tz;
1538 # DateTime::Lite::TimeZone::Local will return an error if the local timezone is not set.
1539 # try-catch
1540 0 local $@;
1541 eval
1542 0 {
1543 0 $tz = DateTime::Lite::TimeZone->new( name => 'local' );
1544 };
1545 0 ▶ if( $@ || !defined( $tz ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($@ or not defined $tz) 0 0 0
Condition0%0/3
$@ or not defined $tz
l!l&&r!l&&!r
000
MC/DC0%0/2
$@ or not defined $tz
$@ not defined $tz
Truth table0%0/3
A or not(B)
A= $@B= not defined $tz
ABresult
1X1
011
000
1546 {
1547 0 $tz = DateTime::Lite::TimeZone->new( name => 'UTC' );
1548 }
1549 0 my $today = DateTime::Lite->now( time_zone => $tz );
1550 0 my $dt_fmt = DateTime::Format::Lite->new(
1551 pattern => '%FT%T%z',
1552 # Unnecessary
1553 # locale => 'en_GB',
1554 time_zone => $tz->name,
1555 );
1556 0 $today->set_formatter( $dt_fmt );
1557 0 my $data = { cookies => $all, updated_on => "$today" };
1558  
1559 0 ▶ my $f = $self->new_file( $file ) || return( $self->pass_error );
Condition0%0/2
$self->new_file($file) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->new_file($file) || (return $self->pass_error)
$self->new_file($file)
Truth table0%0/2
A
A= $self->new_file($file)
Aresult
11
00
1560 0 my $j = JSON->new->allow_nonref->pretty->canonical->convert_blessed;
1561 0 my $json;
1562 # try-catch
1563 $json = eval
1564 0 {
1565 0 $j->encode( $data );
1566 };
1567 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1568 {
1569 0 return( $self->error( "Unable to encode data to json: $@" ) );
1570 }
1571  
1572 0 ▶ $f->open( '>', { binmode => ( $opts->{encrypt} ? 'raw' : 'utf8' ) }) ||
Branch: 2 branches
BranchTrueFalseTotal
$f->open(">", {"binmode", $opts->{"encrypt"} ? "raw" : "utf8"}) or return $self->pass_error($f->error) 0 0 0
$opts->{'encrypt'} ? : 0 0 0
1573 return( $self->pass_error( $f->error ) );
1574 0 ▶ if( $opts->{encrypt} )
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'encrypt'}) { } 0 0 0
1575 {
1576 0 ▶ $self->_load_class( 'Crypt::Misc', { version => CRYPTX_VERSION } ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Crypt::Misc", {"version", "0.074"}) or return $self->pass_error 0 0 0
1577 0 ▶ my $p = $self->_encrypt_objects( @$opts{qw( key algo iv )} ) || return( $self->pass_error );
Condition0%0/2
$self->_encrypt_objects(@$opts{'key', 'algo', 'iv'}) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->_encrypt_objects(@$opts{'key', 'algo', 'iv'}) || (return $self->pass_error)
$self->_encrypt_objects(@$opts{'key', 'algo', 'iv'})
Truth table0%0/2
A
A= $self->_encrypt_objects(@$opts{'key', 'algo', 'iv'})
Aresult
11
00
1578 0 my $crypt = $p->{crypt};
1579 # $value = Crypt::Misc::encode_b64( $crypt->encrypt( "$value", $p->{key}, $p->{iv} ) );
1580 0 my $encrypted = $crypt->encrypt( "$json", @$p{qw( key iv )} );
1581 0 my $b64 = Crypt::Misc::encode_b64( $encrypted );
1582 0 $f->unload( $b64 );
1583 }
1584 else
1585 {
1586 0 $f->unload( $json );
1587 }
1588 0 $f->close;
1589 0 return( $self );
1590 }
1591  
1592 sub save_as_lwp
1593 0 ▶{
Subroutine save_as_lwp: not called CC=18 SCAR=58.3
Pod documented
1594 0 my $self = shift( @_ );
1595 0 ▶ my $file = shift( @_ ) || return( $self->error( "No filename was provided." ) );
Condition0%0/2
shift @_ || (return $self->error('No filename was provided.'))
l!l
00
MC/DC0%0/1
shift @_ || (return $self->error('No filename was provided.'))
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
1596 0 my $opts = $self->_get_args_as_hash( @_ );
1597 0 ▶ $opts->{encrypt} //= 0;
Condition0%0/2
$opts->{"encrypt"} //= 0
l!l
00
MC/DC0%0/1
$opts->{"encrypt"} //= 0
$opts->{"encrypt"}
Truth table0%0/2
A
A= $opts->{"encrypt"}
Aresult
11
00
1598 0 ▶ $opts->{algo} //= '';
Condition0%0/2
$opts->{"algo"} //= ""
l!l
00
MC/DC0%0/1
$opts->{"algo"} //= ""
$opts->{"algo"}
Truth table0%0/2
A
A= $opts->{"algo"}
Aresult
11
00
1599 # Initialisation Vector for encryption
1600 # Re-use it if it was previously set
1601 0 ▶ $opts->{iv} //= $self->_initialisation_vector->scalar || '';
Condition0%0/4
$opts->{"iv"} //= $self->_initialisation_vector->scalar || ""
l!l
00
$self->_initialisation_vector->scalar || ''
l!l
00
MC/DC0%0/1
$opts->{"iv"} //= $self->_initialisation_vector->scalar || ""
$opts->{"iv"}
Truth table0%0/2
A
A= $opts->{"iv"}
Aresult
11
00
1602 0 ▶ $opts->{skip_discard} //= 0;
Condition0%0/2
$opts->{"skip_discard"} //= 0
l!l
00
MC/DC0%0/1
$opts->{"skip_discard"} //= 0
$opts->{"skip_discard"}
Truth table0%0/2
A
A= $opts->{"skip_discard"}
Aresult
11
00
1603 0 ▶ $opts->{skip_expired} //= 0;
Condition0%0/2
$opts->{"skip_expired"} //= 0
l!l
00
MC/DC0%0/1
$opts->{"skip_expired"} //= 0
$opts->{"skip_expired"}
Truth table0%0/2
A
A= $opts->{"skip_expired"}
Aresult
11
00
1604 0 ▶ return( $self->error( "No file to write cookies was specified." ) ) if( !$file );
Branch: 1 branch
BranchTrueFalseTotal
unless $file 0 0 0
1605 0 ▶ my $f = $self->new_file( $file ) || return( $self->pass_error );
Condition0%0/2
$self->new_file($file) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->new_file($file) || (return $self->pass_error)
$self->new_file($file)
Truth table0%0/2
A
A= $self->new_file($file)
Aresult
11
00
1606  
1607 0 my $raw = '';
1608 0 my $p = {};
1609 0 ▶ if( $opts->{encrypt} )
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"encrypt"}) 0 0 0
1610 {
1611 0 ▶ $self->_load_class( 'Crypt::Misc', { version => CRYPTX_VERSION } ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Crypt::Misc", {"version", "0.074"}) or return $self->pass_error 0 0 0
1612 0 ▶ $p = $self->_encrypt_objects( @$opts{qw( key algo iv )} ) || return( $self->pass_error );
Condition0%0/2
$self->_encrypt_objects(@$opts{'key', 'algo', 'iv'}) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->_encrypt_objects(@$opts{'key', 'algo', 'iv'}) || (return $self->pass_error)
$self->_encrypt_objects(@$opts{'key', 'algo', 'iv'})
Truth table0%0/2
A
A= $self->_encrypt_objects(@$opts{'key', 'algo', 'iv'})
Aresult
11
00
1613 }
1614  
1615 0 ▶ my $io = $f->open( '>', { binmode => ( $opts->{encrypt} ? 'raw' : 'utf-8' ) }) ||
Branch: 1 branch
BranchTrueFalseTotal
$opts->{'encrypt'} ? : 0 0 0
Condition0%0/2
$f->open('>', {'binmode', $opts->{'encrypt'} ? 'raw' : 'utf-8'}) || (return $self->error(qq[Unable to write cookies to file "$file": ], $f->error))
l!l
00
MC/DC0%0/1
$f->open('>', {'binmode', $opts->{'encrypt'} ? 'raw' : 'utf-8'}) || (return $self->error(qq[Unable to write cookies to file "$file": ], $f->error))
$f->open('>', {'binmode', $opts->{'encrypt'} ? 'raw' : 'utf-8'})
Truth table0%0/2
A
A= $f->open('>', {'binmode', $opts->{'encrypt'} ? 'raw' : 'utf-8'})
Aresult
11
00
1616 return( $self->error( "Unable to write cookies to file \"$file\": ", $f->error ) );
1617 0 ▶ if( $opts->{encrypt} )
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'encrypt'}) { } 0 0 0
1618 {
1619 0 $raw = "#LWP-Cookies-1.0\n";
1620 }
1621 else
1622 {
1623 0 ▶ $io->print( "#LWP-Cookies-1.0\n" ) || return( $self->error( "Unable to write to cookie file \"$file\": $!" ) );
Branch: 1 branch
BranchTrueFalseTotal
$io->print("#LWP-Cookies-1.0\n") or return $self->error(qq[Unable to write to cookie file "$file": $!]) 0 0 0
1624 }
1625 0 my $now = DateTime::Lite->now;
1626 $self->scan(sub
1627 0 ▶ {
Subroutine __ANON__: not called CC=23 SCAR=63.1
1628 0 my $c = shift( @_ );
1629 0 ▶ return(1) if( $c->discard && $opts->{skip_discard} );
Branch: 1 branch
BranchTrueFalseTotal
if $c->discard and $opts->{"skip_discard"} 0 0 0
Condition0%0/3
$c->discard and $opts->{"skip_discard"}
!ll&&!rl&&r
000
MC/DC0%0/2
$c->discard and $opts->{"skip_discard"}
$c->discard $opts->{"skip_discard"}
Truth table0%0/3
A and B
A= $c->discardB= $opts->{"skip_discard"}
ABresult
0X0
100
111
1630 0 ▶ return(1) if( $c->expires && $c->expires < $now && $opts->{skip_expired} );
Branch: 1 branch
BranchTrueFalseTotal
if $c->expires and $c->expires < $now and $opts->{"skip_expired"} 0 0 0
Condition0%0/6
$c->expires and $c->expires < $now and $opts->{"skip_expired"}
!ll&&!rl&&r
000
$c->expires and $c->expires < $now
!ll&&!rl&&r
000
MC/DC0%0/3
$c->expires and $c->expires < $now and $opts->{"skip_expired"}
$c->expires $c->expires < $now $opts->{"skip_expired"}
Truth table0%0/4
A and B and C
A= $c->expiresB= $c->expires < $nowC= $opts->{"skip_expired"}
ABCresult
0XX0
10X0
1100
1111
1631 0 my $vals = $c->as_hash;
1632 0 ▶ $vals->{path_spec} = 1 if( CORE::length( $vals->{path} ) );
Branch: 1 branch
BranchTrueFalseTotal
if CORE::length $vals->{"path"} 0 0 0
1633 # In HTTP::Cookies logic, version 1 is rfc2109, version 2 is rfc6265
1634 0 $vals->{version} = 2;
1635 0 my $hv = Module::Generic::HeaderValue->new( [CORE::delete( @$vals{qw( name value )} )] );
1636 0 $hv->param( path => sprintf( '"%s"', $vals->{path} ) );
1637 0 $hv->param( domain => $vals->{domain} );
1638 0 ▶ $hv->param( port => $vals->{port} ) if( defined( $vals->{port} ) && CORE::length( $vals->{port} ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $vals->{"port"} and CORE::length $vals->{"port"} 0 0 0
Condition0%0/3
defined $vals->{"port"} and CORE::length $vals->{"port"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $vals->{"port"} and CORE::length $vals->{"port"}
defined $vals->{"port"} CORE::length $vals->{"port"}
Truth table0%0/3
A and B
A= defined $vals->{"port"}B= CORE::length $vals->{"port"}
ABresult
0X0
100
111
1639 0 ▶ $hv->param( path_spec => undef() ) if( defined( $vals->{path_spec} ) && $vals->{path_spec} );
Branch: 1 branch
BranchTrueFalseTotal
if defined $vals->{"path_spec"} and $vals->{"path_spec"} 0 0 0
Condition0%0/3
defined $vals->{"path_spec"} and $vals->{"path_spec"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $vals->{"path_spec"} and $vals->{"path_spec"}
defined $vals->{"path_spec"} $vals->{"path_spec"}
Truth table0%0/3
A and B
A= defined $vals->{"path_spec"}B= $vals->{"path_spec"}
ABresult
0X0
100
111
1640 0 ▶ $hv->param( secure => undef() ) if( defined( $vals->{secure} ) && $vals->{secure} );
Branch: 1 branch
BranchTrueFalseTotal
if defined $vals->{"secure"} and $vals->{"secure"} 0 0 0
Condition0%0/3
defined $vals->{"secure"} and $vals->{"secure"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $vals->{"secure"} and $vals->{"secure"}
defined $vals->{"secure"} $vals->{"secure"}
Truth table0%0/3
A and B
A= defined $vals->{"secure"}B= $vals->{"secure"}
ABresult
0X0
100
111
1641 0 ▶ $hv->param( expires => sprintf( '"%s"', "$vals->{expires}" ) ) if( defined( $vals->{secure} ) && $vals->{expires} );
Branch: 1 branch
BranchTrueFalseTotal
if defined $vals->{"secure"} and $vals->{"expires"} 0 0 0
Condition0%0/3
defined $vals->{"secure"} and $vals->{"expires"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $vals->{"secure"} and $vals->{"expires"}
defined $vals->{"secure"} $vals->{"expires"}
Truth table0%0/3
A and B
A= defined $vals->{"secure"}B= $vals->{"expires"}
ABresult
0X0
100
111
1642 0 ▶ $hv->param( discard => undef() ) if( defined( $vals->{discard} ) && $vals->{discard} );
Branch: 1 branch
BranchTrueFalseTotal
if defined $vals->{"discard"} and $vals->{"discard"} 0 0 0
Condition0%0/3
defined $vals->{"discard"} and $vals->{"discard"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $vals->{"discard"} and $vals->{"discard"}
defined $vals->{"discard"} $vals->{"discard"}
Truth table0%0/3
A and B
A= defined $vals->{"discard"}B= $vals->{"discard"}
ABresult
0X0
100
111
1643 0 ▶ if( defined( $vals->{comment} ) && CORE::length( $vals->{comment} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $vals->{"comment"} and CORE::length $vals->{"comment"}) 0 0 0
Condition0%0/3
defined $vals->{"comment"} and CORE::length $vals->{"comment"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $vals->{"comment"} and CORE::length $vals->{"comment"}
defined $vals->{"comment"} CORE::length $vals->{"comment"}
Truth table0%0/3
A and B
A= defined $vals->{"comment"}B= CORE::length $vals->{"comment"}
ABresult
0X0
100
111
1644 {
1645 0 $vals->{comment} =~ s/(?<!\\)\"/\\\"/g;
1646 0 $hv->param( comment => sprintf( '"%s"', $vals->{comment} ) );
1647 }
1648 0 ▶ $hv->param( commentURL => $vals->{commentURL} ) if( defined( $vals->{commentURL} ) && CORE::length( $vals->{commentURL} ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $vals->{"commentURL"} and CORE::length $vals->{"commentURL"} 0 0 0
Condition0%0/3
defined $vals->{"commentURL"} and CORE::length $vals->{"commentURL"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $vals->{"commentURL"} and CORE::length $vals->{"commentURL"}
defined $vals->{"commentURL"} CORE::length $vals->{"commentURL"}
Truth table0%0/3
A and B
A= defined $vals->{"commentURL"}B= CORE::length $vals->{"commentURL"}
ABresult
0X0
100
111
1649 0 $hv->param( version => $vals->{version} );
1650 0 ▶ if( $opts->{encrypt} )
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'encrypt'}) { } 0 0 0
1651 {
1652 0 $raw .= 'Set-Cookie3: ' . $hv->as_string . "\n";
1653 }
1654 else
1655 {
1656 0 ▶ $io->print( 'Set-Cookie3: ', $hv->as_string, "\n" ) || return( $self->error( "Unable to write to cookie file \"$file\": $!" ) );
Branch: 1 branch
BranchTrueFalseTotal
$io->print("Set-Cookie3: ", $hv->as_string, "\n") or return $self->error(qq[Unable to write to cookie file "$file": $!]) 0 0 0
1657 }
1658 0 });
1659 0 ▶ if( $opts->{encrypt} )
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"encrypt"}) 0 0 0
1660 {
1661 0 my $crypt = $p->{crypt};
1662 0 my $encrypted = $crypt->encrypt( "$raw", @$p{qw( key iv )} );
1663 0 my $b64 = Crypt::Misc::encode_b64( $encrypted );
1664 0 $io->print( $b64 );
1665 }
1666 0 $io->close;
1667 0 return( $self );
1668 }
1669  
1670 sub save_as_mozilla
1671 2 ▶{
Subroutine save_as_mozilla: called CC=103 SCAR=79.8
Pod documented
1672 2 my $self = shift( @_ );
1673 2 ▶ my $file = shift( @_ ) || return( $self->error( "No database file to write cookies was specified." ) );
Condition50%1/2
shift @_ || (return $self->error('No database file to write cookies was specified.'))
l!l
20
MC/DC0%0/1
shift @_ || (return $self->error('No database file to write cookies was specified.'))
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
1674 2 my $opts = $self->_get_args_as_hash( @_ );
1675 2 ▶ $opts->{log_sql} //= '';
Condition100%2/2
$opts->{"log_sql"} //= ""
l!l
11
MC/DC100%1/1
$opts->{"log_sql"} //= ""
$opts->{"log_sql"}
Truth table100%2/2
A
A= $opts->{"log_sql"}
Aresult
11
00
1676 2 ▶ $opts->{overwrite} //= 0;
Condition50%1/2
$opts->{"overwrite"} //= 0
l!l
02
MC/DC0%0/1
$opts->{"overwrite"} //= 0
$opts->{"overwrite"}
Truth table50%1/2
A
A= $opts->{"overwrite"}
Aresult
11
00
1677 2 ▶ $opts->{rollback} //= 0;
Condition50%1/2
$opts->{"rollback"} //= 0
l!l
02
MC/DC0%0/1
$opts->{"rollback"} //= 0
$opts->{"rollback"}
Truth table50%1/2
A
A= $opts->{"rollback"}
Aresult
11
00
1678 2 ▶ $opts->{skip_discard} //= 0;
Condition50%1/2
$opts->{"skip_discard"} //= 0
l!l
02
MC/DC0%0/1
$opts->{"skip_discard"} //= 0
$opts->{"skip_discard"}
Truth table50%1/2
A
A= $opts->{"skip_discard"}
Aresult
11
00
1679 2 ▶ $opts->{skip_expired} //= 0;
Condition50%1/2
$opts->{"skip_expired"} //= 0
l!l
02
MC/DC0%0/1
$opts->{"skip_expired"} //= 0
$opts->{"skip_expired"}
Truth table50%1/2
A
A= $opts->{"skip_expired"}
Aresult
11
00
1680 2 ▶ $opts->{sqlite} //= '';
Condition50%1/2
$opts->{"sqlite"} //= ""
l!l
02
MC/DC0%0/1
$opts->{"sqlite"} //= ""
$opts->{"sqlite"}
Truth table50%1/2
A
A= $opts->{"sqlite"}
Aresult
11
00
1681 2 ▶ $opts->{use_dbi} //= 0;
Condition100%2/2
$opts->{"use_dbi"} //= 0
l!l
11
MC/DC100%1/1
$opts->{"use_dbi"} //= 0
$opts->{"use_dbi"}
Truth table100%2/2
A
A= $opts->{"use_dbi"}
Aresult
11
00
1682 2 ▶ my $sqldb = $self->new_file( $file ) || return( $self->pass_error );
Condition50%1/2
$self->new_file($file) || (return $self->pass_error)
l!l
20
MC/DC0%0/1
$self->new_file($file) || (return $self->pass_error)
$self->new_file($file)
Truth table50%1/2
A
A= $self->new_file($file)
Aresult
11
00
1683 2 my $dbi_error;
1684 my $sqlite_bin;
1685 2 ▶ my $requires_dbi = ( CORE::exists( $opts->{use_dbi} ) && defined( $opts->{use_dbi} ) && $opts->{use_dbi} ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
exists $opts->{'use_dbi'} && defined $opts->{'use_dbi'} && $opts->{'use_dbi'} ? : 1 1 2
Condition50%3/6
exists $opts->{"use_dbi"} and defined $opts->{"use_dbi"} and $opts->{"use_dbi"}
!ll&&!rl&&r
011
exists $opts->{"use_dbi"} and defined $opts->{"use_dbi"}
!ll&&!rl&&r
002
MC/DC33%1/3
exists $opts->{"use_dbi"} and defined $opts->{"use_dbi"} and $opts->{"use_dbi"}
exists $opts->{"use_dbi"} defined $opts->{"use_dbi"} $opts->{"use_dbi"}
Truth table50%2/4
A and B and C
A= exists $opts->{"use_dbi"}B= defined $opts->{"use_dbi"}C= $opts->{"use_dbi"}
ABCresult
0XX0
10X0
1100
1111
1686 2 require version;
1687 2 my $db_file_exists = $sqldb->exists;
1688 2 my $table_moz_cookies_exists = 0;
1689 # As of Firefox 106.0.5 (2022-11-06), the cookie table structure is:
1690 # 'expiry' is a unix timestamp
1691 # 'lastAccessed' and 'creationTime' are in microseconds
1692 2 my $create_table_sql = <<EOT;
1693 CREATE TABLE moz_cookies(
1694 id INTEGER PRIMARY KEY,
1695 originAttributes TEXT NOT NULL DEFAULT '',
1696 name TEXT,
1697 value TEXT,
1698 host TEXT,
1699 path TEXT,
1700 expiry INTEGER,
1701 lastAccessed INTEGER,
1702 creationTime INTEGER,
1703 isSecure INTEGER,
1704 isHttpOnly INTEGER,
1705 inBrowserElement INTEGER DEFAULT 0,
1706 sameSite INTEGER DEFAULT 0,
1707 rawSameSite INTEGER DEFAULT 0,
1708 schemeMap INTEGER DEFAULT 0,
1709 CONSTRAINT moz_uniqueid UNIQUE(name, host, path, originAttributes)
1710 )
1711 EOT
1712 2 my $core_fields =
1713 {
1714 name => { type => 'TEXT', constant => 'SQL_VARCHAR' },
1715 value => { type => 'TEXT', constant => 'SQL_VARCHAR' },
1716 host => { type => 'TEXT', constant => 'SQL_VARCHAR' },
1717 path => { type => 'TEXT', constant => 'SQL_VARCHAR' },
1718 expiry => { type => 'INTEGER', constant => 'SQL_INTEGER' },
1719 isSecure => { type => 'INTEGER', constant => 'SQL_INTEGER' },
1720 sameSite => { type => 'INTEGER', constant => 'SQL_INTEGER' },
1721 isHttpOnly => { type => 'INTEGER', constant => 'SQL_INTEGER' },
1722 lastAccessed => { type => 'INTEGER', constant => 'SQL_INTEGER' },
1723 creationTime => { type => 'INTEGER', constant => 'SQL_INTEGER' },
1724 };
1725 # To hold the cookies data to be saved
1726 2 my $cookies = [];
1727 2 my $now = DateTime::Lite->now;
1728 2 my $can_do_upsert = 0;
1729 my $get_cookies = sub
1730 4 ▶ {
Subroutine __ANON__: called CC=19 SCAR=45.6
1731 4 my $c = shift( @_ );
1732 4 ▶ return(1) if( $c->discard && $opts->{skip_discard} );
Branch: 1 branch
BranchTrueFalseTotal
if $c->discard and $opts->{"skip_discard"} 0 4 4
Condition33%1/3
$c->discard and $opts->{"skip_discard"}
!ll&&!rl&&r
400
MC/DC0%0/2
$c->discard and $opts->{"skip_discard"}
$c->discard $opts->{"skip_discard"}
Truth table33%1/3
A and B
A= $c->discardB= $opts->{"skip_discard"}
ABresult
0X0
100
111
1733 4 ▶ return(1) if( $c->expires && $c->expires < $now && $opts->{skip_expired} );
Branch: 1 branch
BranchTrueFalseTotal
if $c->expires and $c->expires < $now and $opts->{"skip_expired"} 0 4 4
Condition66%4/6
$c->expires and $c->expires < $now and $opts->{"skip_expired"}
!ll&&!rl&&r
220
$c->expires and $c->expires < $now
!ll&&!rl&&r
022
MC/DC0%0/3
$c->expires and $c->expires < $now and $opts->{"skip_expired"}
$c->expires $c->expires < $now $opts->{"skip_expired"}
Truth table50%2/4
A and B and C
A= $c->expiresB= $c->expires < $nowC= $opts->{"skip_expired"}
ABCresult
0XX0
10X0
1100
1111
1734 # Offset 0 is the value, offset 1 is the data type for DBI and offset 2 is the field name used for the sqlite3 binary method
1735 my $row =
1736 [
1737 [$c->name->scalar, $core_fields->{name}->{constant}, 'name'],
1738 [$c->value->scalar, $core_fields->{value}->{constant}, 'value'],
1739 [$c->domain->scalar, $core_fields->{host}->{constant}, 'host'],
1740 [$c->path->scalar, $core_fields->{path}->{constant}, 'path'],
1741 [( $c->expires ? $c->expires->epoch : undef ), $core_fields->{expiry}->{constant}, 'expiry'],
1742 [( $c->secure ? 1 : 0 ), $core_fields->{isSecure}->{constant}, 'isSecure'],
1743 [( $c->same_site->lc eq 'strict' ? 1 : 0 ), $core_fields->{sameSite}->{constant}, 'sameSite'],
1744 [( $c->http_only ? 1 : 0 ), $core_fields->{isHttpOnly}->{constant}, 'isHttpOnly'],
1745 [( $c->accessed_on ? ( $c->accessed_on->epoch * 1000000 ) : undef ), $core_fields->{lastAccessed}->{constant}, 'lastAccessed'],
1746 4 ▶ [( $c->created_on ? ( $c->created_on->epoch * 1000000 ) : undef ), $core_fields->{creationTime}->{constant}, 'creationTime'],
Branch: 6 branches
BranchTrueFalseTotal
$c->expires ? : 4 0 4
$c->secure ? : 4 0 4
$c->same_site->lc eq 'strict' ? : 0 4 4
$c->http_only ? : 2 2 4
$c->accessed_on ? : 4 0 4
$c->created_on ? : 4 0 4
1747 ];
1748 4 ▶ if( $can_do_upsert )
Branch: 1 branch
BranchTrueFalseTotal
if ($can_do_upsert) 0 4 4
1749 {
1750 0 push( @$row, [$c->value->scalar, $core_fields->{value}->{constant}, 'value'] );
1751 0 ▶ push( @$row, [( $c->expires ? $c->expires->epoch : undef ), $core_fields->{expiry}->{constant}, 'expiry'] );
Branch: 1 branch
BranchTrueFalseTotal
$c->expires ? : 0 0 0
1752 0 ▶ push( @$row, [( $c->secure ? 1 : 0 ), $core_fields->{isSecure}->{constant}, 'isSecure'] );
Branch: 1 branch
BranchTrueFalseTotal
$c->secure ? : 0 0 0
1753 0 ▶ push( @$row, [( $c->same_site->lc eq 'strict' ? 1 : 0 ), $core_fields->{sameSite}->{constant}, 'sameSite'] );
Branch: 1 branch
BranchTrueFalseTotal
$c->same_site->lc eq 'strict' ? : 0 0 0
1754 0 ▶ push( @$row, [( $c->http_only ? 1 : 0 ), $core_fields->{isHttpOnly}->{constant}, 'isHttpOnly'] );
Branch: 1 branch
BranchTrueFalseTotal
$c->http_only ? : 0 0 0
1755 0 ▶ push( @$row, [( $c->accessed_on ? ( $c->accessed_on->epoch * 1000000 ) : undef ), $core_fields->{lastAccessed}->{constant}, 'lastAccessed'] );
Branch: 1 branch
BranchTrueFalseTotal
$c->accessed_on ? : 0 0 0
1756 0 ▶ push( @$row, [( $c->created_on ? ( $c->created_on->epoch * 1000000 ) : undef ), $core_fields->{creationTime}->{constant}, 'creationTime'] );
Branch: 1 branch
BranchTrueFalseTotal
$c->created_on ? : 0 0 0
1757 }
1758 4 push( @$cookies, $row );
1759 2 };
1760  
1761 # From SQLite version 3.24.0
1762 # update if there is a constraint violation on 'moz_uniqueid', i.e. name, host, path, originAttributes
1763 2 my $upsert_sql = <<EOT;
1764 INSERT INTO moz_cookies (name, value, host, path, expiry, isSecure, sameSite, isHttpOnly, lastAccessed, creationTime)
1765 VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
1766 ON CONFLICT(name, host, path, originAttributes)
1767 DO UPDATE SET value = ?, expiry = ?, isSecure = ?, sameSite = ?, isHttpOnly = ?, lastAccessed = ?, creationTime = ?
1768 EOT
1769 2 my $insert_ignore_sql = <<EOT;
1770 INSERT OR IGNORE INTO moz_cookies (name, value, host, path, expiry, isSecure, sameSite, isHttpOnly, lastAccessed, creationTime)
1771 VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
1772 EOT
1773 2 my $insert_replace_sql = <<EOT;
1774 INSERT OR REPLACE INTO moz_cookies (name, value, host, path, expiry, isSecure, sameSite, isHttpOnly, lastAccessed, creationTime)
1775 VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
1776 EOT
1777  
1778 # Required version for upsert
1779 2 my $req_v = version->parse( '3.24.0' );
1780 2 my $log_file;
1781 2 ▶ if( $opts->{log_sql} )
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"log_sql"}) 1 1 2
1782 {
1783 1 ▶ $log_file = $self->new_file( $opts->{log_sql} ) ||
Condition50%1/2
$self->new_file($opts->{'log_sql'}) || (return $self->pass_error)
l!l
10
MC/DC0%0/1
$self->new_file($opts->{'log_sql'}) || (return $self->pass_error)
$self->new_file($opts->{'log_sql'})
Truth table50%1/2
A
A= $self->new_file($opts->{'log_sql'})
Aresult
11
00
1784 return( $self->pass_error );
1785 }
1786  
1787 # If the user explicitly required the use of DBI/DBD::SQLite; or
1788 # the user has not explicitly required the use of DBI/DBD::SQLite nor of sqlite3 binary
1789 2 ▶ if( $requires_dbi ||
Branch: 1 branch
BranchTrueFalseTotal
if ($requires_dbi or not $opts->{"use_dbi"} || $opts->{"sqlite"}) 2 0 2
Condition50%3/6
$requires_dbi or not $opts->{"use_dbi"} || $opts->{"sqlite"}
l!l&&r!l&&!r
110
$opts->{'use_dbi'} || $opts->{'sqlite'}
l!l&&r!l&&!r
001
MC/DC0%0/3
$requires_dbi or not $opts->{"use_dbi"} || $opts->{"sqlite"}
$requires_dbi $opts->{'use_dbi'} $opts->{'sqlite'}
Truth table50%2/4
A or not(B || C)
A= $requires_dbiB= $opts->{'use_dbi'}C= $opts->{'sqlite'}
ABCresult
1XX1
0001
01X0
0010
1790 ( !$opts->{use_dbi} && !$opts->{sqlite} ) )
1791 {
1792 eval
1793 2 {
1794 2 require DBI;
1795 2 require DBD::SQLite;
1796 };
1797 2 ▶ $dbi_error = $@ if( $@ );
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 2 2
1798 # User explicitly required the use of DBI/DBD::SQLite, but it failed, so we return an error
1799 2 ▶ if( defined( $dbi_error ) && exists( $opts->{use_dbi} ) && defined( $opts->{use_dbi} ) && $opts->{use_dbi} )
Branch: 2 branches
BranchTrueFalseTotal
if (defined $dbi_error and exists $opts->{'use_dbi'} and defined $opts->{'use_dbi'} and $opts->{'use_dbi'}) { } 0 2 2
elsif (not defined $dbi_error) { } 2 0 2
Condition33%3/9
defined $dbi_error and exists $opts->{"use_dbi"} and defined $opts->{"use_dbi"} and $opts->{"use_dbi"}
!ll&&!rl&&r
200
defined $dbi_error and exists $opts->{"use_dbi"} and defined $opts->{"use_dbi"}
!ll&&!rl&&r
200
defined $dbi_error and exists $opts->{"use_dbi"}
!ll&&!rl&&r
200
MC/DC0%0/4
defined $dbi_error and exists $opts->{"use_dbi"} and defined $opts->{"use_dbi"} and $opts->{"use_dbi"}
defined $dbi_error exists $opts->{"use_dbi"} defined $opts->{"use_dbi"} $opts->{"use_dbi"}
Truth table20%1/5
A and B and C and D
A= defined $dbi_errorB= exists $opts->{"use_dbi"}C= defined $opts->{"use_dbi"}D= $opts->{"use_dbi"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1800 {
1801 0 return( $self->error( "Unable to load either DBI or DBD::SQLite: $@" ) );
1802 }
1803 elsif( !defined( $dbi_error ) )
1804 {
1805 2 foreach my $f ( keys( %$core_fields ) )
1806 {
1807 my $code = DBI->can( $core_fields->{ $f }->{constant} ) ||
1808 20 ▶ die( "Invalid data type '", $core_fields->{ $f }->{constant}, "' for DBI." );
Condition50%1/2
'DBI'->can($core_fields->{$f}{'constant'}) || die(q[Invalid data type '], $core_fields->{$f}{'constant'}, q[' for DBI.])
l!l
200
MC/DC0%0/1
'DBI'->can($core_fields->{$f}{'constant'}) || die(q[Invalid data type '], $core_fields->{$f}{'constant'}, q[' for DBI.])
'DBI'->can($core_fields->{$f}{'constant'})
Truth table50%1/2
A
A= 'DBI'->can($core_fields->{$f}{'constant'})
Aresult
11
00
1809 20 $core_fields->{ $f }->{constant} = $code->();
1810 }
1811  
1812 # try-catch;
1813 2 local $@;
1814 2 my $err;
1815 eval
1816 2 {
1817 2 ▶ my $dbh = DBI->connect( "dbi:SQLite:dbname=${sqldb}", '', '', { RaiseError => 1, AutoCommit => 1 } ) ||
Condition50%1/2
'DBI'->connect("dbi:SQLite:dbname=$sqldb", '', '', {'RaiseError', 1, 'AutoCommit', 1}) || die("Unable to connect to SQLite database file ${sqldb}: ", $DBI::errstr)
l!l
20
MC/DC0%0/1
'DBI'->connect("dbi:SQLite:dbname=$sqldb", '', '', {'RaiseError', 1, 'AutoCommit', 1}) || die("Unable to connect to SQLite database file ${sqldb}: ", $DBI::errstr)
'DBI'->connect("dbi:SQLite:dbname=$sqldb", '', '', {'RaiseError', 1, 'AutoCommit', 1})
Truth table50%1/2
A
A= 'DBI'->connect("dbi:SQLite:dbname=$sqldb", '', '', {'RaiseError', 1, 'AutoCommit', 1})
Aresult
11
00
1818 die( "Unable to connect to SQLite database file ${sqldb}: ", $DBI::errstr );
1819 2 ▶ if( $opts->{log_sql} )
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"log_sql"}) 1 1 2
1820 {
1821 1 ▶ if( !$log_file->open( '>>', { binmode => 'utf-8', autoflush => 1 } ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($log_file->open(">>", {"binmode", "utf-8", "autoflush", 1})) 0 1 1
1822 {
1823 0 $err = $log_file->error;
1824 0 return;
1825 }
1826 $dbh->sqlite_trace(sub
1827 4 ▶ {
Subroutine __ANON__: called CC=1 SCAR=0.0
1828 4 my $sql = shift( @_ );
1829 4 $log_file->print( $sql, "\n" );
1830 1 });
1831 }
1832 2 my $rv;
1833 2 my $version_sql = q{SELECT sqlite_version()};
1834 2 ▶ my $version_sth = $dbh->prepare( $version_sql ) ||
Condition50%1/2
$dbh->prepare($version_sql) || die('Errror preparing sql query to get the SQLite driver version: ', $dbh->errstr, "\nSQL query was $version_sql")
l!l
20
MC/DC0%0/1
$dbh->prepare($version_sql) || die('Errror preparing sql query to get the SQLite driver version: ', $dbh->errstr, "\nSQL query was $version_sql")
$dbh->prepare($version_sql)
Truth table50%1/2
A
A= $dbh->prepare($version_sql)
Aresult
11
00
1835 die( "Errror preparing sql query to get the SQLite driver version: ", $dbh->errstr, "\nSQL query was ${version_sql}" );
1836 2 ▶ $rv = $version_sth->execute() ||
Condition50%1/2
$version_sth->execute || die('Errror executing sql query to get the SQLite driver version: ', $version_sth->errstr, "\nSQL query was $version_sql")
l!l
20
MC/DC0%0/1
$version_sth->execute || die('Errror executing sql query to get the SQLite driver version: ', $version_sth->errstr, "\nSQL query was $version_sql")
$version_sth->execute
Truth table50%1/2
A
A= $version_sth->execute
Aresult
11
00
1837 die( "Errror executing sql query to get the SQLite driver version: ", $version_sth->errstr, "\nSQL query was ${version_sql}" );
1838 2 my $sqlite_version = $version_sth->fetchrow;
1839 2 $version_sth->finish;
1840 2 my $sql_v = version->parse( $sqlite_version );
1841  
1842 2 ▶ if( $db_file_exists )
Branch: 1 branch
BranchTrueFalseTotal
if ($db_file_exists) 0 2 2
1843 {
1844 # my $tbl_check = $dbh->table_info( undef, undef, 'moz_cookies', 'TABLE' ) ||
1845 0 ▶ my $tbl_check = $dbh->prepare( q{SELECT name FROM sqlite_master WHERE type IN ('table') AND name IS 'moz_cookies'} ) ||
Condition0%0/2
$dbh->prepare(q[SELECT name FROM sqlite_master WHERE type IN ('table') AND name IS 'moz_cookies']) || die("Error preparing sql query to check for existence of table 'moz_cookies' in SQLite database file ${sqldb}: ", $dbh->errstr)
l!l
00
MC/DC0%0/1
$dbh->prepare(q[SELECT name FROM sqlite_master WHERE type IN ('table') AND name IS 'moz_cookies']) || die("Error preparing sql query to check for existence of table 'moz_cookies' in SQLite database file ${sqldb}: ", $dbh->errstr)
$dbh->prepare(q[SELECT name FROM sqlite_master WHERE type IN ('table') AND name IS 'moz_cookies'])
Truth table0%0/2
A
A= $dbh->prepare(q[SELECT name FROM sqlite_master WHERE type IN ('table') AND name IS 'moz_cookies'])
Aresult
11
00
1846 die( "Error preparing sql query to check for existence of table 'moz_cookies' in SQLite database file ${sqldb}: ", $dbh->errstr );
1847 0 ▶ $rv = $tbl_check->execute || die( "Error executing query to check existence of table 'moz_cookies': ", $tbl_check->errstr );
Condition0%0/2
$tbl_check->execute || die(q[Error executing query to check existence of table 'moz_cookies': ], $tbl_check->errstr)
l!l
00
MC/DC0%0/1
$tbl_check->execute || die(q[Error executing query to check existence of table 'moz_cookies': ], $tbl_check->errstr)
$tbl_check->execute
Truth table0%0/2
A
A= $tbl_check->execute
Aresult
11
00
1848 0 $table_moz_cookies_exists = $tbl_check->fetchrow;
1849 0 $tbl_check->finish;
1850 0 ▶ if( $table_moz_cookies_exists )
Branch: 1 branch
BranchTrueFalseTotal
if ($table_moz_cookies_exists) 0 0 0
1851 {
1852 # Drop the table altogether
1853 0 ▶ if( $opts->{overwrite} )
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'overwrite'}) { } 0 0 0
1854 {
1855 0 my $drop_sql = q{DROP TABLE moz_cookies};
1856 0 ▶ my $drop_sth = $dbh->prepare( $drop_sql ) ||
Condition0%0/2
$dbh->prepare($drop_sql) || die("Error preparing query to drop existing table moz_cookies in SQLIte database file ${sqldb}: ", $dbh->errstr, "\nSQL query was ${$drop_sql;}")
l!l
00
MC/DC0%0/1
$dbh->prepare($drop_sql) || die("Error preparing query to drop existing table moz_cookies in SQLIte database file ${sqldb}: ", $dbh->errstr, "\nSQL query was ${$drop_sql;}")
$dbh->prepare($drop_sql)
Truth table0%0/2
A
A= $dbh->prepare($drop_sql)
Aresult
11
00
1857 0 die( "Error preparing query to drop existing table moz_cookies in SQLIte database file ${sqldb}: ", $dbh->errstr, "\nSQL query was ${$drop_sql}" );
1858 0 ▶ $rv = $drop_sth->execute() ||
Condition0%0/2
$drop_sth->execute || die("Error executing query to drop existing table moz_cookies in SQLIte database file ${sqldb}: ", $drop_sth->errstr, "\nSQL query was ${$drop_sql;}")
l!l
00
MC/DC0%0/1
$drop_sth->execute || die("Error executing query to drop existing table moz_cookies in SQLIte database file ${sqldb}: ", $drop_sth->errstr, "\nSQL query was ${$drop_sql;}")
$drop_sth->execute
Truth table0%0/2
A
A= $drop_sth->execute
Aresult
11
00
1859 0 die( "Error executing query to drop existing table moz_cookies in SQLIte database file ${sqldb}: ", $drop_sth->errstr, "\nSQL query was ${$drop_sql}" );
1860 0 $drop_sth->finish;
1861 0 $table_moz_cookies_exists = 0;
1862 }
1863 else
1864 {
1865 # PRAGMA table_info() returns cid, name, type, notnull, dflt_value, pk
1866 0 my $tbl_info_sql = q{PRAGMA TABLE_INFO(moz_cookies)};
1867 0 ▶ my $tbl_info_sth = $dbh->prepare( $tbl_info_sql ) ||
Condition0%0/2
$dbh->prepare($tbl_info_sql) || die(q[Error while trying to prepare query to get the existing table 'moz_cookies' information: ], $dbh->errstr, "\nSQL query is: $tbl_info_sql")
l!l
00
MC/DC0%0/1
$dbh->prepare($tbl_info_sql) || die(q[Error while trying to prepare query to get the existing table 'moz_cookies' information: ], $dbh->errstr, "\nSQL query is: $tbl_info_sql")
$dbh->prepare($tbl_info_sql)
Truth table0%0/2
A
A= $dbh->prepare($tbl_info_sql)
Aresult
11
00
1868 die( "Error while trying to prepare query to get the existing table 'moz_cookies' information: ", $dbh->errstr, "\nSQL query is: ${tbl_info_sql}" );
1869 0 ▶ $rv = $tbl_info_sth->execute ||
Condition0%0/2
$tbl_info_sth->execute || die(q[Error while trying to execute query to get the existing table 'moz_cookies' information: ], $tbl_info_sth->errstr, "\nSQL query is: $tbl_info_sql")
l!l
00
MC/DC0%0/1
$tbl_info_sth->execute || die(q[Error while trying to execute query to get the existing table 'moz_cookies' information: ], $tbl_info_sth->errstr, "\nSQL query is: $tbl_info_sql")
$tbl_info_sth->execute
Truth table0%0/2
A
A= $tbl_info_sth->execute
Aresult
11
00
1870 die( "Error while trying to execute query to get the existing table 'moz_cookies' information: ", $tbl_info_sth->errstr, "\nSQL query is: ${tbl_info_sql}" );
1871 0 my $all = $tbl_info_sth->fetchall_arrayref( {} );
1872 0 $tbl_info_sth->finish;
1873 # Check existing table field for missing fields
1874 0 my $fields = {};
1875 0 foreach my $this ( @$all )
1876 {
1877 0 $fields->{ $this->{name} } = $this;
1878 }
1879 0 my $missing = [];
1880 0 my $bad_datatype = [];
1881 0 foreach my $f ( keys( %$core_fields ) )
1882 {
1883 0 ▶ if( !CORE::exists( $fields->{ $f } ) )
Branch: 2 branches
BranchTrueFalseTotal
if (not exists $fields->{$f}) { } 0 0 0
elsif ($core_fields->{$f}{'type'} ne uc $fields->{$f}{'type'}) { } 0 0 0
1884 {
1885 0 push( @$missing, $f );
1886 }
1887 elsif( $core_fields->{ $f }->{type} ne uc( $fields->{ $f }->{type} ) )
1888 {
1889 0 push( @$bad_datatype, $f );
1890 }
1891 }
1892 0 ▶ if( scalar( @$missing ) || scalar( @$bad_datatype ) )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$missing or scalar @$bad_datatype) 0 0 0
Condition0%0/2
scalar @$missing or scalar @$bad_datatype
l!l
00
MC/DC0%0/1
scalar @$missing or scalar @$bad_datatype
scalar @$missing
Truth table0%0/2
A
A= scalar @$missing
Aresult
11
00
1893 {
1894 0 $self->error( sprintf( "Found an existing SQLite database file ${sqldb} with a table 'moz_cookies', but found %d missing fields (%s) and %d fields with inappropriate data type (%s)", scalar( @$missing ), join( ', ', @$missing ), scalar( @$bad_datatype ), join( ', ', @$bad_datatype ) ) );
1895 0 $err = $self->error;
1896 0 return;
1897 }
1898 }
1899 }
1900 }
1901  
1902 2 my $errors = [];
1903 2 my $insert_sth;
1904 # Create the table if it does not exist
1905 2 ▶ if( !$table_moz_cookies_exists )
Branch: 1 branch
BranchTrueFalseTotal
if (not $table_moz_cookies_exists) { } 2 0 2
1906 {
1907 2 ▶ my $create_table_sth = $dbh->prepare( $create_table_sql ) ||
Condition50%1/2
$dbh->prepare($create_table_sql) || die("Error preparing query to create table moz_cookies in SQLite database file ${sqldb}: ", $dbh->errstr, "\nSQL query was: $create_table_sql")
l!l
20
MC/DC0%0/1
$dbh->prepare($create_table_sql) || die("Error preparing query to create table moz_cookies in SQLite database file ${sqldb}: ", $dbh->errstr, "\nSQL query was: $create_table_sql")
$dbh->prepare($create_table_sql)
Truth table50%1/2
A
A= $dbh->prepare($create_table_sql)
Aresult
11
00
1908 die( "Error preparing query to create table moz_cookies in SQLite database file ${sqldb}: ", $dbh->errstr, "\nSQL query was: ${create_table_sql}" );
1909 2 ▶ my $rv = $create_table_sth->execute() ||
Condition50%1/2
$create_table_sth->execute || die("Error executing query to create table moz_cookies in SQLite database file ${sqldb}: ", $create_table_sth->errstr, "\nSQL query was: $create_table_sql")
l!l
20
MC/DC0%0/1
$create_table_sth->execute || die("Error executing query to create table moz_cookies in SQLite database file ${sqldb}: ", $create_table_sth->errstr, "\nSQL query was: $create_table_sql")
$create_table_sth->execute
Truth table50%1/2
A
A= $create_table_sth->execute
Aresult
11
00
1910 die( "Error executing query to create table moz_cookies in SQLite database file ${sqldb}: ", $create_table_sth->errstr, "\nSQL query was: ${create_table_sql}" );
1911 2 $create_table_sth->finish;
1912 2 ▶ $insert_sth = $dbh->prepare( $insert_ignore_sql ) ||
Condition50%1/2
$dbh->prepare($insert_ignore_sql) || die("Error preparing the sql query to add/ignore cookies to 'moz_cookies' in SQLite database file ${sqldb}: ", $dbh->errstr, "\nSQL query was: $insert_ignore_sql")
l!l
20
MC/DC0%0/1
$dbh->prepare($insert_ignore_sql) || die("Error preparing the sql query to add/ignore cookies to 'moz_cookies' in SQLite database file ${sqldb}: ", $dbh->errstr, "\nSQL query was: $insert_ignore_sql")
$dbh->prepare($insert_ignore_sql)
Truth table50%1/2
A
A= $dbh->prepare($insert_ignore_sql)
Aresult
11
00
1913 die( "Error preparing the sql query to add/ignore cookies to 'moz_cookies' in SQLite database file ${sqldb}: ", $dbh->errstr, "\nSQL query was: ${insert_ignore_sql}" );
1914 }
1915 # or update the data
1916 else
1917 {
1918 0 ▶ $can_do_upsert = ( $sql_v >= $req_v ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$sql_v >= $req_v ? : 0 0 0
1919 # if version is greater or equal to 3.24.0 we can do upsert, otherwise we do insert replace
1920 0 ▶ if( $can_do_upsert )
Branch: 1 branch
BranchTrueFalseTotal
if ($can_do_upsert) { } 0 0 0
1921 {
1922 0 ▶ $insert_sth = $dbh->prepare( $upsert_sql ) ||
Condition0%0/2
$dbh->prepare($upsert_sql) || die("Error preparing the sql query to add cookies to 'moz_cookies' in SQLite database file ${sqldb}: ", $dbh->errstr, "\nSQL query was: $upsert_sql")
l!l
00
MC/DC0%0/1
$dbh->prepare($upsert_sql) || die("Error preparing the sql query to add cookies to 'moz_cookies' in SQLite database file ${sqldb}: ", $dbh->errstr, "\nSQL query was: $upsert_sql")
$dbh->prepare($upsert_sql)
Truth table0%0/2
A
A= $dbh->prepare($upsert_sql)
Aresult
11
00
1923 die( "Error preparing the sql query to add cookies to 'moz_cookies' in SQLite database file ${sqldb}: ", $dbh->errstr, "\nSQL query was: ${upsert_sql}" );
1924 }
1925 else
1926 {
1927 0 ▶ $insert_sth = $dbh->prepare( $insert_replace_sql ) ||
Condition0%0/2
$dbh->prepare($insert_replace_sql) || die("Error preparing the sql query to add/replace cookies to 'moz_cookies' in SQLite database file ${sqldb}: ", $dbh->errstr, "\nSQL query was: $insert_replace_sql")
l!l
00
MC/DC0%0/1
$dbh->prepare($insert_replace_sql) || die("Error preparing the sql query to add/replace cookies to 'moz_cookies' in SQLite database file ${sqldb}: ", $dbh->errstr, "\nSQL query was: $insert_replace_sql")
$dbh->prepare($insert_replace_sql)
Truth table0%0/2
A
A= $dbh->prepare($insert_replace_sql)
Aresult
11
00
1928 die( "Error preparing the sql query to add/replace cookies to 'moz_cookies' in SQLite database file ${sqldb}: ", $dbh->errstr, "\nSQL query was: ${insert_replace_sql}" );
1929 }
1930 }
1931  
1932 # NOTE: call to scan() must be after setting $can_do_upsert
1933 2 $self->scan( $get_cookies );
1934  
1935 2 ▶ if( $opts->{rollback} )
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"rollback"}) 0 2 2
1936 {
1937 0 $dbh->begin_work;
1938 }
1939  
1940 2 foreach my $c ( @$cookies )
1941 {
1942 eval
1943 4 {
1944 4 ▶ for( my $i = 0; $i < scalar( @$c ); $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @$c) 40 4 44
1945 {
1946 40 ▶ $insert_sth->bind_param( $i + 1, $c->[$i]->[0], $c->[$i]->[1] ) ||
Branch: 1 branch
BranchTrueFalseTotal
$insert_sth->bind_param($i + 1, $c->[$i][0], $c->[$i][1]) or die "Error binding parameter No. ", $i + 1, " with value '", $c->[$i][0], "': ", $insert_sth->errstr 40 0 40
1947 die( "Error binding parameter No. ", ( $i + 1 ), " with value '", $c->[$i]->[0], "': ", $insert_sth->errstr );
1948 }
1949 4 ▶ $rv = $insert_sth->execute() ||
Condition50%1/2
$insert_sth->execute || die(q[Failed to execute query to insert cookie '], $c->name->scalar, q[' -> ], $insert_sth->errstr, "\nQuery was $insert_ignore_sql")
l!l
40
MC/DC0%0/1
$insert_sth->execute || die(q[Failed to execute query to insert cookie '], $c->name->scalar, q[' -> ], $insert_sth->errstr, "\nQuery was $insert_ignore_sql")
$insert_sth->execute
Truth table50%1/2
A
A= $insert_sth->execute
Aresult
11
00
1950 die( "Failed to execute query to insert cookie '", $c->name->scalar, "' -> ", $insert_sth->errstr, "\nQuery was ${insert_ignore_sql}" );
1951 };
1952 4 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 4 4
1953 {
1954 # offset 0 -> name, offset 2 -> domain
1955 0 push( @$errors, [$c->[0], $c->[2], $@] );
1956 0 ▶ if( $opts->{rollback} )
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"rollback"}) 0 0 0
1957 {
1958 0 $dbh->rollback;
1959 0 last;
1960 }
1961 }
1962 }
1963 2 $insert_sth->finish;
1964 2 $dbh->disconnect;
1965 };
1966 2 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 2 2
1967 {
1968 0 ▶ if( $requires_dbi )
Branch: 1 branch
BranchTrueFalseTotal
if ($requires_dbi) { } 0 0 0
1969 {
1970 0 return( $self->error( "Error trying to save mozilla cookies to SQLite database ${sqldb} using DBI: $@" ) );
1971 }
1972 else
1973 {
1974 0 $dbi_error = $@;
1975 0 ▶ warn( "Non fatal error occurred while trying to save mozilla cookies to SQLite database ${sqldb} using DBI: $@\n" ) if( $self->_warnings_is_enabled );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_warnings_is_enabled 0 0 0
1976 }
1977 }
1978 2 ▶ return( $self->pass_error( $err ) ) if( defined( $err ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $err 0 2 2
1979 }
1980 }
1981  
1982 # If the user did not require exclusively the use of DBI, but required the use of sqlite3 binary
1983 # the user did not require the use of DBI nor the use of sqlite3 binary
1984 2 ▶ if( ( defined( $dbi_error ) && !$requires_dbi ) ||
Branch: 1 branch
BranchTrueFalseTotal
if (defined $dbi_error and not $requires_dbi or exists $opts->{"sqlite"} and defined $opts->{"sqlite"} and CORE::length $opts->{"sqlite"}) 0 2 2
Condition33%4/12
defined $dbi_error and not $requires_dbi or exists $opts->{"sqlite"} and defined $opts->{"sqlite"} and CORE::length $opts->{"sqlite"}
l!l&&r!l&&!r
002
defined $dbi_error and not $requires_dbi
!ll&&!rl&&r
200
exists $opts->{"sqlite"} and defined $opts->{"sqlite"} and CORE::length $opts->{"sqlite"}
!ll&&!rl&&r
020
exists $opts->{"sqlite"} and defined $opts->{"sqlite"}
!ll&&!rl&&r
002
MC/DC0%0/5
defined $dbi_error and not $requires_dbi or exists $opts->{"sqlite"} and defined $opts->{"sqlite"} and CORE::length $opts->{"sqlite"}
defined $dbi_error not $requires_dbi exists $opts->{"sqlite"} defined $opts->{"sqlite"} CORE::length $opts->{"sqlite"}
Truth table11%1/9
A and not(B) or C and D and E
A= defined $dbi_errorB= not $requires_dbiC= exists $opts->{"sqlite"}D= defined $opts->{"sqlite"}E= CORE::length $opts->{"sqlite"}
ABCDEresult
11XXX1
0X1111
101111
0X0XX0
0X10X0
0X1100
100XX0
1010X0
101100
1985 ( exists( $opts->{sqlite} ) && defined( $opts->{sqlite} ) && CORE::length( $opts->{sqlite} ) ) )
1986 {
1987 # If the user required specific sqlite3 binary
1988 0 ▶ if( exists( $opts->{sqlite} ) && defined( $opts->{sqlite} ) && CORE::length( $opts->{sqlite} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts->{'sqlite'} and defined $opts->{'sqlite'} and CORE::length $opts->{'sqlite'}) { } 0 0 0
Condition0%0/6
exists $opts->{"sqlite"} and defined $opts->{"sqlite"} and CORE::length $opts->{"sqlite"}
!ll&&!rl&&r
000
exists $opts->{"sqlite"} and defined $opts->{"sqlite"}
!ll&&!rl&&r
000
MC/DC0%0/3
exists $opts->{"sqlite"} and defined $opts->{"sqlite"} and CORE::length $opts->{"sqlite"}
exists $opts->{"sqlite"} defined $opts->{"sqlite"} CORE::length $opts->{"sqlite"}
Truth table0%0/4
A and B and C
A= exists $opts->{"sqlite"}B= defined $opts->{"sqlite"}C= CORE::length $opts->{"sqlite"}
ABCresult
0XX0
10X0
1100
1111
1989 {
1990 0 ▶ if( !-e( $opts->{sqlite} ) )
Branch: 2 branches
BranchTrueFalseTotal
if (not -e $opts->{'sqlite'}) { } 0 0 0
elsif (not -x $opts->{'sqlite'}) { } 0 0 0
1991 {
1992 0 return( $self->error( "sqlite3 binary path provided \"$opts->{sqlite}\" does not exist." ) );
1993 }
1994 elsif( !-x( $opts->{sqlite} ) )
1995 {
1996 0 return( $self->error( "sqlite3 binary path provided \"$opts->{sqlite}\" is not executable by user id $>" ) );
1997 }
1998 0 $sqlite_bin = $opts->{sqlite};
1999 }
2000 else
2001 {
2002 0 require File::Which;
2003 0 my $bin = File::Which::which( 'sqlite3' );
2004 0 ▶ if( !defined( $bin ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $bin) 0 0 0
2005 {
2006 0 return( $self->error( "DBI and/or DBD::SQLite modules are not installed and I could not find thr sqlite3 binary anywhere." ) );
2007 }
2008 0 $sqlite_bin = $bin;
2009 }
2010  
2011 0 my $fh;
2012 # Get SQLite version
2013 # open( $fh, '-|', $sqlite_bin, "SELECT sqlite_version()" ) ||
2014 0 ▶ open( $fh, '-|', $sqlite_bin, "--version" ) ||
Branch: 1 branch
BranchTrueFalseTotal
open $fh, "-|", $sqlite_bin, "--version" or return $self->error("Failed to execute sqlite3 binary $sqlite_bin to get its version number: $!") 0 0 0
2015 return( $self->error( "Failed to execute sqlite3 binary ${sqlite_bin} to get its version number: $!" ) );
2016 0 my $sqlite_version = <$fh>;
2017 0 my $sql_v;
2018 0 ▶ if( defined( $sqlite_version ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $sqlite_version) 0 0 0
2019 {
2020 0 chomp( $sqlite_version );
2021 0 $sqlite_version = [split( /[[:blank:]\h]+/, $sqlite_version )]->[0];
2022 0 $sql_v = version->parse( $sqlite_version );
2023 0 close( $fh );
2024 }
2025  
2026 # Check if table moz_cookies exists
2027 0 ▶ open( $fh, '-|', $sqlite_bin, "${sqldb}", "SELECT name FROM sqlite_master WHERE type IN ('table') AND name IS 'moz_cookies'" ) ||
Branch: 1 branch
BranchTrueFalseTotal
open $fh, "-|", $sqlite_bin, "$sqldb", "SELECT name FROM sqlite_master WHERE type IN ('table') AND name IS 'moz_cookies'" or return $self->error("Failed to execute sqlite3 binary $sqlite_bin to check if table moz_cookies exists: $!") 0 0 0
2028 return( $self->error( "Failed to execute sqlite3 binary ${sqlite_bin} to check if table moz_cookies exists: $!" ) );
2029 # chomp( $table_moz_cookies_exists = <$fh> );
2030 0 $table_moz_cookies_exists = <$fh>;
2031 0 ▶ $table_moz_cookies_exists //= '';
Condition0%0/2
$table_moz_cookies_exists //= ""
l!l
00
MC/DC0%0/1
$table_moz_cookies_exists //= ""
$table_moz_cookies_exists
Truth table0%0/2
A
A= $table_moz_cookies_exists
Aresult
11
00
2032 0 chomp( $table_moz_cookies_exists );
2033 0 close( $fh );
2034  
2035 # Now, get the data to save
2036 0 ▶ open( $fh, '|-', $sqlite_bin, '--bail', "${sqldb}" ) ||
Branch: 1 branch
BranchTrueFalseTotal
open $fh, "|-", $sqlite_bin, "--bail", "$sqldb" or return $self->error("Failed to execute sqlite3 binary $sqlite_bin to save all mozilla cookies to database ${sqldb}: $!") 0 0 0
2037 return( $self->error( "Failed to execute sqlite3 binary ${sqlite_bin} to save all mozilla cookies to database ${sqldb}: $!" ) );
2038 0 $fh->autoflush;
2039 0 ▶ if( $opts->{log_sql} )
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"log_sql"}) 0 0 0
2040 {
2041 0 ▶ print( $fh ".trace ${log_file}\n" ) ||
Branch: 1 branch
BranchTrueFalseTotal
print $fh ".trace $log_file\n" or return $self->error("Failed to print sqlite command to enable logging to file ${log_file}: $!") 0 0 0
2042 return( $self->error( "Failed to print sqlite command to enable logging to file ${log_file}: $!" ) );
2043 }
2044 0 ▶ if( $table_moz_cookies_exists && $opts->{overwrite} )
Branch: 1 branch
BranchTrueFalseTotal
if ($table_moz_cookies_exists and $opts->{"overwrite"}) 0 0 0
Condition0%0/3
$table_moz_cookies_exists and $opts->{"overwrite"}
!ll&&!rl&&r
000
MC/DC0%0/2
$table_moz_cookies_exists and $opts->{"overwrite"}
$table_moz_cookies_exists $opts->{"overwrite"}
Truth table0%0/3
A and B
A= $table_moz_cookies_existsB= $opts->{"overwrite"}
ABresult
0X0
100
111
2045 {
2046 0 ▶ print( $fh "DROP TABLE IF EXISTS moz_cookies;\n" ) ||
Branch: 1 branch
BranchTrueFalseTotal
print $fh "DROP TABLE IF EXISTS moz_cookies;\n" or return $self->error("Failed to print sql commands to sqlite3 binary $sqlite_bin to save all mozilla cookies to database ${sqldb}: $!") 0 0 0
2047 return( $self->error( "Failed to print sql commands to sqlite3 binary ${sqlite_bin} to save all mozilla cookies to database ${sqldb}: $!" ) );
2048 0 $table_moz_cookies_exists = 0;
2049 }
2050  
2051 0 ▶ if( $opts->{rollback} )
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"rollback"}) 0 0 0
2052 {
2053 0 ▶ print( $fh "BEGIN TRANSACTION;\n" ) ||
Branch: 1 branch
BranchTrueFalseTotal
print $fh "BEGIN TRANSACTION;\n" or return $self->error("Failed to print sql commands to sqlite3 binary $sqlite_bin to save all mozilla cookies to database ${sqldb}: $!") 0 0 0
2054 return( $self->error( "Failed to print sql commands to sqlite3 binary ${sqlite_bin} to save all mozilla cookies to database ${sqldb}: $!" ) );
2055 }
2056 0 my $template;
2057 0 ▶ if( !$table_moz_cookies_exists )
Branch: 1 branch
BranchTrueFalseTotal
if (not $table_moz_cookies_exists) { } 0 0 0
2058 {
2059 0 chomp( $create_table_sql );
2060 0 ▶ print( $fh "${create_table_sql};\n" ) ||
Branch: 1 branch
BranchTrueFalseTotal
print $fh "$create_table_sql;\n" or return $self->error("Failed to print sql commands to sqlite3 binary $sqlite_bin to save all mozilla cookies to database ${sqldb}: $!") 0 0 0
2061 return( $self->error( "Failed to print sql commands to sqlite3 binary ${sqlite_bin} to save all mozilla cookies to database ${sqldb}: $!" ) );
2062 0 $template = $insert_ignore_sql;
2063 }
2064 else
2065 {
2066 0 ▶ $can_do_upsert = ( defined( $sql_v ) && $sql_v >= $req_v ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $sql_v && $sql_v >= $req_v ? : 0 0 0
Condition0%0/3
defined $sql_v and $sql_v >= $req_v
!ll&&!rl&&r
000
MC/DC0%0/2
defined $sql_v and $sql_v >= $req_v
defined $sql_v $sql_v >= $req_v
Truth table0%0/3
A and B
A= defined $sql_vB= $sql_v >= $req_v
ABresult
0X0
100
111
2067 # if version is greater or equal to 3.24.0 we can do upsert, otherwise we do insert replace
2068 0 ▶ if( $can_do_upsert )
Branch: 1 branch
BranchTrueFalseTotal
if ($can_do_upsert) { } 0 0 0
2069 {
2070 0 $template = $upsert_sql;
2071 }
2072 else
2073 {
2074 0 $template = $insert_replace_sql;
2075 }
2076 }
2077 0 chomp( $template );
2078 # This stores the data in $cookies array reference
2079 # NOTE: call to scan() must be after setting $can_do_upsert
2080 0 $self->scan( $get_cookies );
2081 0 my $row = $cookies->[0];
2082 0 foreach my $ref ( @$row )
2083 {
2084 0 ▶ if( $core_fields->{ $ref->[2] }->{constant} eq 'SQL_INTEGER' )
Branch: 1 branch
BranchTrueFalseTotal
if ($$core_fields{$ref->[2]}{'constant'} eq 'SQL_INTEGER') { } 0 0 0
2085 {
2086 0 $template =~ s/\?/%s/;
2087 }
2088 else
2089 {
2090 0 $template =~ s/\?/'%s'/;
2091 }
2092 }
2093  
2094 0 foreach my $row ( @$cookies )
2095 {
2096 0 my $sql = sprintf( $template, map( $_->[0], @$row ) );
2097 print( $fh "${sql};\n" ) || do
2098 0 ▶ {
Branch: 1 branch
BranchTrueFalseTotal
print $fh "$sql;\n" or do { my $err = $!; if ($opts->{"rollback"}) { print $fh "ROLLBACK TRANSACTION;\n"; } ; return $self->error("Failed to print sql commands to sqlite3 binary $sqlite_bin to save all mozilla cookies to database ${sqldb}: $err") } 0 0 0
2099 0 my $err = $!;
2100 0 ▶ if( $opts->{rollback} )
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"rollback"}) 0 0 0
2101 {
2102 0 print( $fh "ROLLBACK TRANSACTION;\n" );
2103 }
2104 0 return( $self->error( "Failed to print sql commands to sqlite3 binary ${sqlite_bin} to save all mozilla cookies to database ${sqldb}: ${err}" ) );
2105 };
2106 }
2107  
2108 0 ▶ if( $opts->{rollback} )
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"rollback"}) 0 0 0
2109 {
2110 0 ▶ print( $fh "END TRANSACTION;\n" ) ||
Branch: 1 branch
BranchTrueFalseTotal
print $fh "END TRANSACTION;\n" or return $self->error("Failed to print sql commands to sqlite3 binary $sqlite_bin to save all mozilla cookies to database ${sqldb}: $!") 0 0 0
2111 return( $self->error( "Failed to print sql commands to sqlite3 binary ${sqlite_bin} to save all mozilla cookies to database ${sqldb}: $!" ) );
2112 }
2113 0 close( $fh );
2114 }
2115  
2116 2 ▶ if( $opts->{log_sql} &&
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"log_sql"} and defined $log_file and $log_file->opened) 1 1 2
Condition66%4/6
$opts->{"log_sql"} and defined $log_file and $log_file->opened
!ll&&!rl&&r
101
$opts->{"log_sql"} and defined $log_file
!ll&&!rl&&r
101
MC/DC33%1/3
$opts->{"log_sql"} and defined $log_file and $log_file->opened
$opts->{"log_sql"} defined $log_file $log_file->opened
Truth table50%2/4
A and B and C
A= $opts->{"log_sql"}B= defined $log_fileC= $log_file->opened
ABCresult
0XX0
10X0
1100
1111
2117 defined( $log_file ) &&
2118 $log_file->opened )
2119 {
2120 1 $log_file->close;
2121 }
2122 2 return( $self );
2123 }
2124  
2125 sub save_as_netscape
2126 0 ▶{
Subroutine save_as_netscape: not called CC=7 SCAR=40.3
Pod documented
2127 0 my $self = shift( @_ );
2128 0 my $opts = $self->_get_args_as_hash( @_ );
2129 0 ▶ $opts->{file} //= '';
Condition0%0/2
$opts->{"file"} //= ""
l!l
00
MC/DC0%0/1
$opts->{"file"} //= ""
$opts->{"file"}
Truth table0%0/2
A
A= $opts->{"file"}
Aresult
11
00
2130 0 ▶ $opts->{skip_discard} //= 0;
Condition0%0/2
$opts->{"skip_discard"} //= 0
l!l
00
MC/DC0%0/1
$opts->{"skip_discard"} //= 0
$opts->{"skip_discard"}
Truth table0%0/2
A
A= $opts->{"skip_discard"}
Aresult
11
00
2131 0 ▶ $opts->{skip_expired} //= 0;
Condition0%0/2
$opts->{"skip_expired"} //= 0
l!l
00
MC/DC0%0/1
$opts->{"skip_expired"} //= 0
$opts->{"skip_expired"}
Truth table0%0/2
A
A= $opts->{"skip_expired"}
Aresult
11
00
2132 0 ▶ return( $self->error( "No file to write cookies was specified." ) ) if( !$opts->{file} );
Branch: 1 branch
BranchTrueFalseTotal
unless $opts->{"file"} 0 0 0
2133 0 ▶ my $f = $self->new_file( $opts->{file} ) || return( $self->pass_error );
Condition0%0/2
$self->new_file($opts->{'file'}) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->new_file($opts->{'file'}) || (return $self->pass_error)
$self->new_file($opts->{'file'})
Truth table0%0/2
A
A= $self->new_file($opts->{'file'})
Aresult
11
00
2134 0 ▶ my $io = $f->open( '>', { binmode => 'utf-8' }) ||
Condition0%0/2
$f->open('>', {'binmode', 'utf-8'}) || (return $self->error(qq[Unable to write cookies to file "$opts->{'file'}": ], $f->error))
l!l
00
MC/DC0%0/1
$f->open('>', {'binmode', 'utf-8'}) || (return $self->error(qq[Unable to write cookies to file "$opts->{'file'}": ], $f->error))
$f->open('>', {'binmode', 'utf-8'})
Truth table0%0/2
A
A= $f->open('>', {'binmode', 'utf-8'})
Aresult
11
00
2135 return( $self->error( "Unable to write cookies to file \"$opts->{file}\": ", $f->error ) );
2136 0 $io->print( "# Netscape HTTP Cookie File:\n" );
2137 0 my $now = DateTime::Lite->now;
2138 $self->scan(sub
2139 0 ▶ {
Subroutine __ANON__: not called CC=8 SCAR=42.8
2140 0 my $c = shift( @_ );
2141 0 ▶ return(1) if( $c->discard && $opts->{skip_discard} );
Branch: 1 branch
BranchTrueFalseTotal
if $c->discard and $opts->{"skip_discard"} 0 0 0
Condition0%0/3
$c->discard and $opts->{"skip_discard"}
!ll&&!rl&&r
000
MC/DC0%0/2
$c->discard and $opts->{"skip_discard"}
$c->discard $opts->{"skip_discard"}
Truth table0%0/3
A and B
A= $c->discardB= $opts->{"skip_discard"}
ABresult
0X0
100
111
2142 0 ▶ return(1) if( $c->expires && $c->expires < $now && $opts->{skip_expired} );
Branch: 1 branch
BranchTrueFalseTotal
if $c->expires and $c->expires < $now and $opts->{"skip_expired"} 0 0 0
Condition0%0/6
$c->expires and $c->expires < $now and $opts->{"skip_expired"}
!ll&&!rl&&r
000
$c->expires and $c->expires < $now
!ll&&!rl&&r
000
MC/DC0%0/3
$c->expires and $c->expires < $now and $opts->{"skip_expired"}
$c->expires $c->expires < $now $opts->{"skip_expired"}
Truth table0%0/4
A and B and C
A= $c->expiresB= $c->expires < $nowC= $opts->{"skip_expired"}
ABCresult
0XX0
10X0
1100
1111
2143 0 my @temp = ( $c->domain );
2144 0 ▶ push( @temp, $c->domain->substr( 1, 1 ) eq '.' ? 'TRUE' : 'FALSE' );
Branch: 1 branch
BranchTrueFalseTotal
$c->domain->substr(1, 1) eq '.' ? : 0 0 0
2145 0 push( @temp, $c->path );
2146 0 ▶ push( @temp, $c->secure ? 'TRUE' : 'FALSE' );
Branch: 1 branch
BranchTrueFalseTotal
$c->secure ? : 0 0 0
2147 0 push( @temp, $c->expires->epoch );
2148 0 push( @temp, $c->name );
2149 0 push( @temp, $c->value );
2150 0 $io->print( join( "\t", @temp ), "\n" );
2151 0 });
2152 0 $io->close;
2153 0 return( $self );
2154 }
2155  
2156 # For backward compatibility with HTTP::Cookies
2157 2 ▶sub scan { return( shift->do( @_ ) ); }
Subroutine scan: called CC=1 SCAR=0.0
Pod documented
2158  
2159 # NOTE: the secret key to be used to decrypt or encrypt the cookie jar file
2160 0 ▶sub secret { return( shift->_set_get_scalar( 'secret', @_ ) ); }
Subroutine secret: not called CC=1 SCAR=6.9
Pod documented
2161  
2162 sub set
2163 1 ▶{
Subroutine set: called CC=9 SCAR=26.2
Pod documented
2164 1 my $self = shift( @_ );
2165 1 my $c = shift( @_ );
2166 1 my $opts = $self->_get_args_as_hash( @_ );
2167 1 ▶ return( $self->error( "No cookie name was provided to set." ) ) if( !$c->name->length );
Branch: 1 branch
BranchTrueFalseTotal
unless $c->name->length 0 1 1
2168 1 ▶ return( $self->error( "Cookie value should be an object." ) ) if( !Scalar::Util::blessed( $c ) );
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($c) 0 1 1
2169 1 ▶ return( $self->error( "Cookie object does not have any as_string method." ) ) if( !$c->can( 'as_string' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $c->can("as_string") 0 1 1
2170 1 ▶ $opts->{response} //= '';
Condition50%1/2
$opts->{"response"} //= ""
l!l
10
MC/DC0%0/1
$opts->{"response"} //= ""
$opts->{"response"}
Truth table50%1/2
A
A= $opts->{"response"}
Aresult
11
00
2171 1 my $r = $self->request;
2172 1 ▶ if( $r )
Branch: 2 branches
BranchTrueFalseTotal
if ($r) { } 0 1 1
elsif ($opts->{'response'} and $self->_is_object($opts->{'response'}) and $opts->{'response'}->can('header')) { } 1 0 1
2173 {
2174 0 $r->err_headers_out->add( 'Set-Cookie', $c->as_string );
2175 }
2176 ▶ elsif( $opts->{response} && $self->_is_object( $opts->{response} ) && $opts->{response}->can( 'header' ) )
Condition33%2/6
$opts->{"response"} and $self->_is_object($opts->{"response"}) and $opts->{"response"}->can("header")
!ll&&!rl&&r
001
$opts->{"response"} and $self->_is_object($opts->{"response"})
!ll&&!rl&&r
001
MC/DC0%0/3
$opts->{"response"} and $self->_is_object($opts->{"response"}) and $opts->{"response"}->can("header")
$opts->{"response"} $self->_is_object($opts->{"response"}) $opts->{"response"}->can("header")
Truth table25%1/4
A and B and C
A= $opts->{"response"}B= $self->_is_object($opts->{"response"})C= $opts->{"response"}->can("header")
ABCresult
0XX0
10X0
1100
1111
2177 {
2178 1 $opts->{response}->header( 'Set-Cookie' => $c->as_string );
2179 }
2180 else
2181 {
2182 0 return( "Set-Cookie: " . $c->as_string );
2183 }
2184 1 return( $self );
2185 }
2186  
2187 # NOTE: cookie jar file type, e.g.: json, lwp or netscape
2188 0 ▶sub type { return( shift->_set_get_scalar( 'type', @_ ) ); }
Subroutine type: not called CC=1 SCAR=6.9
Pod documented
2189  
2190 # This is used to autosave cookie jar when called before global destruction phase in END.
2191 sub _autosave
2192 26 ▶{
Subroutine _autosave: called CC=10 SCAR=23.4
2193 26 my $self = shift( @_ );
2194 26 ▶ return if( $self->{_autosaved} || !$self->{_autosave_ready} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_autosaved"} or not $self->{"_autosave_ready"} 7 19 26
Condition100%3/3
$self->{"_autosaved"} or not $self->{"_autosave_ready"}
l!l&&r!l&&!r
4319
MC/DC100%2/2
$self->{"_autosaved"} or not $self->{"_autosave_ready"}
$self->{"_autosaved"} not $self->{"_autosave_ready"}
Truth table100%3/3
A or not(B)
A= $self->{"_autosaved"}B= not $self->{"_autosave_ready"}
ABresult
1X1
011
000
2195 19 my $file = $self->file;
2196 19 ▶ if( $self->autosave && $file )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->autosave and $file) 7 12 19
Condition100%3/3
$self->autosave and $file
!ll&&!rl&&r
397
MC/DC100%2/2
$self->autosave and $file
$self->autosave $file
Truth table100%3/3
A and B
A= $self->autosaveB= $file
ABresult
0X0
100
111
2197 {
2198 7 my $encrypt = $self->encrypt;
2199 7 my $type = $self->type;
2200 7 my $type2sub =
2201 {
2202 json => \&save,
2203 lwp => \&save_as_lwp,
2204 mozilla => \&save_as_mozilla,
2205 netscape => \&save_as_netscape,
2206 };
2207 7 ▶ if( !CORE::exists( $type2sub->{ $type } ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $type2sub->{$type}) 0 7 7
2208 {
2209 0 ▶ warn( "Unknown cookie jar type '$type'. This can be either json, lwp or netscape\n" ) if( $self->_warnings_is_enabled );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_warnings_is_enabled 0 0 0
2210 0 return;
2211 }
2212  
2213 7 my $unloader = $type2sub->{ $type };
2214 7 my $saved;
2215 7 ▶ if( $encrypt )
Branch: 1 branch
BranchTrueFalseTotal
if ($encrypt) { } 1 6 7
2216 {
2217 1 $saved = $unloader->( $self, $file,
2218 algo => $self->algo,
2219 key => $self->secret,
2220 );
2221 }
2222 else
2223 {
2224 6 $saved = $unloader->( $self, $file );
2225 }
2226 7 ▶ if( !$saved )
Branch: 1 branch
BranchTrueFalseTotal
unless ($saved) 2 5 7
2227 {
2228 2 ▶ warn( $self->error, "\n" ) if( $self->_warnings_is_enabled );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_warnings_is_enabled 0 2 2
2229 2 return;
2230 }
2231 # Mark it as saved to prevent DESTROY from saving it again.
2232 5 $self->{_autosaved} = 1;
2233 }
2234 17 return( $self );
2235 }
2236  
2237 8 ▶sub _cookies { return( shift->_set_get_array_as_object( '_cookies', @_ ) ); }
Subroutine _cookies: called CC=1 SCAR=0.0
2238  
2239 sub _domain_match
2240 0 ▶{
Subroutine _domain_match: not called CC=5 SCAR=34.0
2241 0 my $self = shift( @_ );
2242 0 ▶ my $host = lc( shift( @_ ) // '' );
Condition0%0/2
shift @_ // ""
l!l
00
MC/DC0%0/1
shift @_ // ""
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
2243 0 ▶ my $domain = lc( shift( @_ ) // '' );
Condition0%0/2
shift @_ // ""
l!l
00
MC/DC0%0/1
shift @_ // ""
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
2244 0 ▶ return(1) if( $host eq $domain );
Branch: 1 branch
BranchTrueFalseTotal
if $host eq $domain 0 0 0
2245 0 ▶ return(1) if( $host =~ /\.\Q$domain\E$/ );
Branch: 1 branch
BranchTrueFalseTotal
if $host =~ /\.\Q$domain\E$/ 0 0 0
2246 0 return(0);
2247 }
2248  
2249 sub _encrypt_objects
2250 0 ▶{
Subroutine _encrypt_objects: not called CC=16 SCAR=56.1
2251 0 my $self = shift( @_ );
2252 0 my( $key, $algo, $iv ) = @_;
2253 0 ▶ return( $self->error( "Key provided is empty!" ) ) if( !defined( $key ) || !CORE::length( "$key" ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $key and CORE::length "$key" 0 0 0
Condition0%0/3
defined $key and CORE::length "$key"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $key and CORE::length "$key"
defined $key CORE::length "$key"
Truth table0%0/3
A and B
A= defined $keyB= CORE::length "$key"
ABresult
0X0
100
111
2254 0 ▶ return( $self->error( "No algorithm was provided to encrypt cookie value. You can choose any <NAME> for which there exists Crypt::Cipher::<NAME>" ) ) if( !defined( $algo ) || !CORE::length( "$algo" ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $algo and CORE::length "$algo" 0 0 0
Condition0%0/3
defined $algo and CORE::length "$algo"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $algo and CORE::length "$algo"
defined $algo CORE::length "$algo"
Truth table0%0/3
A and B
A= defined $algoB= CORE::length "$algo"
ABresult
0X0
100
111
2255 0 ▶ $self->_load_class( 'Crypt::Mode::CBC', { version => CRYPTX_VERSION } ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Crypt::Mode::CBC", {"version", "0.074"}) or return $self->pass_error 0 0 0
2256 0 ▶ $self->_load_class( 'Bytes::Random::Secure' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Bytes::Random::Secure") or return $self->pass_error 0 0 0
2257 # try-catch
2258 0 local $@;
2259 my $crypt = eval
2260 0 {
2261 0 Crypt::Mode::CBC->new( "$algo" );
2262 };
2263 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
2264 {
2265 0 return( $self->error( "Error getting the encryption objects for algorithm \"$algo\": $@" ) );
2266 }
2267 0 ▶ $crypt or return( $self->error( "Unable to create a Crypt::Mode::CBC object." ) );
Branch: 1 branch
BranchTrueFalseTotal
$crypt or return $self->error("Unable to create a Crypt::Mode::CBC object.") 0 0 0
2268  
2269 0 my $class = "Crypt::Cipher::${algo}";
2270 0 ▶ $self->_load_class( $class ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class($class) or return $self->pass_error 0 0 0
2271  
2272 0 my( $key_len, $block_len );
2273 eval
2274 0 {
2275 0 $key_len = $class->keysize;
2276 0 $block_len = $class->blocksize;
2277 };
2278 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
2279 {
2280 0 return( $self->error( "Error getting the encryption key and block size for algorithm \"$algo\": $@" ) );
2281 }
2282 0 ▶ return( $self->error( "The size of the key provided (", CORE::length( $key ), ") does not match the minimum key size required for this algorithm \"$algo\" (${key_len})." ) ) if( CORE::length( $key ) < $key_len );
Branch: 1 branch
BranchTrueFalseTotal
if CORE::length $key < $key_len 0 0 0
2283 # Generate an "IV", i.e. Initialisation Vector based on the required block size
2284 0 ▶ if( defined( $iv ) && CORE::length( "$iv" ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $iv and CORE::length "$iv") { } 0 0 0
Condition0%0/3
defined $iv and CORE::length "$iv"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $iv and CORE::length "$iv"
defined $iv CORE::length "$iv"
Truth table0%0/3
A and B
A= defined $ivB= CORE::length "$iv"
ABresult
0X0
100
111
2285 {
2286 0 ▶ if( CORE::length( $iv ) != $block_len )
Branch: 1 branch
BranchTrueFalseTotal
if (CORE::length $iv != $block_len) 0 0 0
2287 {
2288 0 return( $self->error( "The Initialisation Vector provided for cookie encryption has a length (", CORE::length( $iv ), ") which does not match the algorithm ($algo) size requirement ($block_len). Please refer to the Cookie::Jar package documentation." ) );
2289 }
2290 }
2291 else
2292 {
2293 $iv = eval
2294 0 {
2295 0 Bytes::Random::Secure::random_bytes( $block_len );
2296 };
2297 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
2298 {
2299 0 return( $self->error( "Error trying to get $block_len secure random bytes: $@" ) );
2300 }
2301 # Save it for decryption
2302 0 $self->_initialisation_vector( $iv );
2303 }
2304 0 my $key_pack = pack( 'H' x $key_len, $key );
2305 0 my $iv_pack = pack( 'H' x $block_len, $iv );
2306 0 return({ 'crypt' => $crypt, key => $key_pack, iv => $iv_pack });
2307 }
2308  
2309 6 ▶sub _index { return( shift->_set_get_hash_as_mix_object( '_index', @_ ) ); }
Subroutine _index: called CC=1 SCAR=0.0
2310  
2311 # For cookies file encryption
2312 0 ▶sub _initialisation_vector { return( shift->_set_get_scalar_as_object( '_initialisation_vector', @_ ) ); }
Subroutine _initialisation_vector: not called CC=1 SCAR=6.9
2313  
2314 sub _normalize_path # so that plain string compare can be used
2315 0 ▶{
Subroutine _normalize_path: not called CC=3 SCAR=24.8
2316 0 my $self = shift( @_ );
2317 0 my $str = shift( @_ );
2318 0 my $x;
2319 0 $str =~ s{
2320 %([0-9a-fA-F][0-9a-fA-F])
2321 }
2322 {
2323 0 $x = uc( $1 );
2324 0 ▶ $x eq '2F' || $x eq '25' ? "%$x" : pack( 'C', hex( $x ) );
Branch: 1 branch
BranchTrueFalseTotal
$x eq '2F' || $x eq '25' ? : 0 0 0
Condition0%0/3
$x eq "2F" or $x eq 25
l!l&&r!l&&!r
000
MC/DC0%0/2
$x eq "2F" or $x eq 25
$x eq "2F" $x eq 25
Truth table0%0/3
A or B
A= $x eq "2F"B= $x eq 25
ABresult
1X1
011
000
2325 }egx;
2326 0 $str =~ s/([\0-\x20\x7f-\xff])/sprintf( '%%%02X', ord( $1 ) )/eg;
2327 0 return( $str );
2328 }
2329  
2330 sub DESTROY
2331 14 ▶{
Subroutine DESTROY: called CC=3 SCAR=11.3
2332 14 my $self = shift( @_ );
2333 # <https://perldoc.perl.org/perlobj#Destructors>
2334 14 local( $., $@, $!, $^E, $? );
2335 # Remove the entry, so the registry does not grow indefinitely especially under mod_perl.
2336 14 ▶ CORE::delete( $LIVE_JARS->{ Scalar::Util::refaddr( $self ) } ) if( $LIVE_JARS );
Branch: 1 branch
BranchTrueFalseTotal
if $Cookie::Jar::LIVE_JARS 14 0 14
2337 14 ▶ return if( Module::Generic::_in_global_destruction() );
Branch: 1 branch
BranchTrueFalseTotal
if Module::Generic::_in_global_destruction() 0 14 14
2338 14 $self->_autosave;
2339 };
2340  
2341 # NOTE: END
2342 END
2343 8 ▶{
Subroutine END: called CC=3 SCAR=11.2
2344 # Save live jars before global destruction, without keeping them alive in the registry.
2345 8 foreach my $jar ( values( %$LIVE_JARS ) )
2346 {
2347 4 ▶ next unless( defined( $jar ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $jar 0 4 4
2348 4 $jar->_autosave;
2349 }
2350 }
2351  
2352 8 1;
2353 # NOTE: POD
2354 __END__
↑ Summary Cookie/Domain.pm »