| 1 | package HTTP::Session::State::Cookie; | ||||||||||||||||||||||||||||
| 2 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use HTTP::Session::State::Base; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use Carp (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use Scalar::Util (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 4 | our $COOKIE_CLASS = 'CGI::Cookie'; | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 4 | __PACKAGE__->mk_accessors(qw/name path domain expires secure samesite httponly/); | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | { | ||||||||||||||||||||||||||||
| 12 | 4 | my $required = 0; | |||||||||||||||||||||||||||
| 13 | 49 | ▶ | sub _cookie_class { | ||||||||||||||||||||||||||
|
Subroutine
_cookie_class: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 14 | 49 | my $class = shift; | |||||||||||||||||||||||||||
| 15 | 49 | ▶ | unless ($required) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 16 | 4 | (my $klass = $COOKIE_CLASS) =~ s!::!/!g; | |||||||||||||||||||||||||||
| 17 | 4 | $klass .= ".pm"; | |||||||||||||||||||||||||||
| 18 | 4 | require $klass; | |||||||||||||||||||||||||||
| 19 | 4 | $required++; | |||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||
| 21 | 49 | return $COOKIE_CLASS | |||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 4 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||||||
| 26 | 30 | my $class = shift; | |||||||||||||||||||||||||||
| 27 | 0 | ▶ | my %args = ref($_[0]) ? %{$_[0]} : @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 28 | # set default values | ||||||||||||||||||||||||||||
| 29 | 30 | ▶ | $args{name} ||= 'http_session_sid'; | ||||||||||||||||||||||||||
|
Condition100%2/2
$args{"name"} ||= "http_session_sid"
MC/DC100%1/1
$args{"name"} ||= "http_session_sid"
$args{"name"}
Truth table100%2/2
A
A= $args{"name"}
| |||||||||||||||||||||||||||||
| 30 | 30 | ▶ | $args{path} ||= '/'; | ||||||||||||||||||||||||||
|
Condition100%2/2
$args{"path"} ||= "/"
MC/DC100%1/1
$args{"path"} ||= "/"
$args{"path"}
Truth table100%2/2
A
A= $args{"path"}
| |||||||||||||||||||||||||||||
| 31 | 30 | bless {%args}, $class; | |||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 30 | ▶ | sub get_session_id { | ||||||||||||||||||||||||||
|
Subroutine
get_session_id: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 35 | 30 | my ($self, $req) = @_; | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 30 | ▶ | my $cookie_header = $ENV{HTTP_COOKIE} || (Scalar::Util::blessed($req) ? $req->header('Cookie') : $req->{HTTP_COOKIE}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$ENV{'HTTP_COOKIE'} || (builtin::blessed($req) ? $req->header('Cookie') : $req->{'HTTP_COOKIE'})
MC/DC100%2/2
$ENV{'HTTP_COOKIE'} || (builtin::blessed($req) ? $req->header('Cookie') : $req->{'HTTP_COOKIE'})
$ENV{'HTTP_COOKIE'}
(builtin::blessed($req) ? $req->header('Cookie') : $req->{'HTTP_COOKIE'})
Truth table100%3/3
A || B
A= $ENV{'HTTP_COOKIE'}B= (builtin::blessed($req) ? $req->header('Cookie') : $req->{'HTTP_COOKIE'})
| |||||||||||||||||||||||||||||
| 38 | 30 | ▶ | return unless $cookie_header; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 28 | my %jar = _cookie_class()->parse($cookie_header); | |||||||||||||||||||||||||||
| 41 | 28 | my $cookie = $jar{$self->name}; | |||||||||||||||||||||||||||
| 42 | 28 | ▶ | return $cookie ? $cookie->value : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 21 | ▶ | sub response_filter { | ||||||||||||||||||||||||||
|
Subroutine
response_filter: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 46 | 21 | my ($self, $session_id, $res) = @_; | |||||||||||||||||||||||||||
| 47 | 21 | ▶ | Carp::croak "missing session_id" unless $session_id; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 19 | $self->header_filter($session_id, $res); | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 21 | ▶ | sub header_filter { | ||||||||||||||||||||||||||
|
Subroutine
header_filter: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 53 | 21 | my ($self, $session_id, $res) = @_; | |||||||||||||||||||||||||||
| 54 | 21 | ▶ | Carp::croak "missing session_id" unless $session_id; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | my $cookie = _cookie_class()->new( | ||||||||||||||||||||||||||||
| 57 | 21 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||
| 58 | 21 | my %options = ( | |||||||||||||||||||||||||||
| 59 | -name => $self->name, | ||||||||||||||||||||||||||||
| 60 | -value => $session_id, | ||||||||||||||||||||||||||||
| 61 | -path => $self->path, | ||||||||||||||||||||||||||||
| 62 | ); | ||||||||||||||||||||||||||||
| 63 | 21 | ▶ | $options{'-domain'} = $self->domain if $self->domain; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | 21 | ▶ | $options{'-expires'} = $self->expires if $self->expires; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | 21 | ▶ | $options{'-secure'} = $self->secure if $self->secure; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | 21 | ▶ | $options{'-samesite'} = $self->samesite if $self->samesite; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | 21 | ▶ | $options{'-httponly'} = $self->httponly if $self->httponly; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | 21 | %options; | |||||||||||||||||||||||||||
| 69 | 21 | }->() | |||||||||||||||||||||||||||
| 70 | ); | ||||||||||||||||||||||||||||
| 71 | 21 | ▶ | if (Scalar::Util::blessed($res)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | 20 | $res->header( 'Set-Cookie' => $cookie->as_string ); | |||||||||||||||||||||||||||
| 73 | 20 | $res; | |||||||||||||||||||||||||||
| 74 | } else { | ||||||||||||||||||||||||||||
| 75 | 1 | push @{$res->[1]}, 'Set-Cookie' => $cookie->as_string; | |||||||||||||||||||||||||||
| 76 | 1 | $res; | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 4 | 1; | |||||||||||||||||||||||||||
| 81 | __END__ | ||||||||||||||||||||||||||||