| 1 | 3 | ▶ | use 5.008001; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 2 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | package Dancer2::Session::Cookie; | ||||||||||||||||||||||||||||
| 6 | 3 | our $AUTHORITY = 'cpan:YANICK'; | |||||||||||||||||||||||||||
| 7 | # ABSTRACT: Dancer 2 session storage in secure cookies | ||||||||||||||||||||||||||||
| 8 | # VERSION | ||||||||||||||||||||||||||||
| 9 | 3 | $Dancer2::Session::Cookie::VERSION = '0.009'; | |||||||||||||||||||||||||||
| 10 | 3 | ▶ | use Session::Storage::Secure 0.011 (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 3 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 3 | ▶ | use Dancer2::Core::Types; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | #--------------------------------------------------------------------------# | ||||||||||||||||||||||||||||
| 16 | # Attributes | ||||||||||||||||||||||||||||
| 17 | #--------------------------------------------------------------------------# | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 3 | has secret_key => ( | |||||||||||||||||||||||||||
| 21 | is => 'ro', | ||||||||||||||||||||||||||||
| 22 | isa => Str, | ||||||||||||||||||||||||||||
| 23 | required => 1, | ||||||||||||||||||||||||||||
| 24 | ); | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 3 | has default_duration => ( | |||||||||||||||||||||||||||
| 28 | is => 'ro', | ||||||||||||||||||||||||||||
| 29 | isa => Int, | ||||||||||||||||||||||||||||
| 30 | predicate => 1, | ||||||||||||||||||||||||||||
| 31 | ); | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 3 | has with_request_address => ( | |||||||||||||||||||||||||||
| 35 | is => 'ro', | ||||||||||||||||||||||||||||
| 36 | isa => Bool, | ||||||||||||||||||||||||||||
| 37 | ); | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 3 | has _store => ( | |||||||||||||||||||||||||||
| 40 | is => 'lazy', | ||||||||||||||||||||||||||||
| 41 | isa => InstanceOf ['Session::Storage::Secure'], | ||||||||||||||||||||||||||||
| 42 | handles => { | ||||||||||||||||||||||||||||
| 43 | '_freeze' => 'encode', | ||||||||||||||||||||||||||||
| 44 | '_retrieve' => 'decode', | ||||||||||||||||||||||||||||
| 45 | }, | ||||||||||||||||||||||||||||
| 46 | ); | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 67 | ▶ | before [qw/ _freeze _retrieve /] => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 49 | 67 | my $self = shift; | |||||||||||||||||||||||||||
| 50 | 67 | ▶ | return unless $self->with_request_address; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | 3 | $self->_store->{secret_key} = join '-', $self->secret_key, $self->request->address; | |||||||||||||||||||||||||||
| 52 | 3 | }; | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 7 | ▶ | sub _build__store { | ||||||||||||||||||||||||||
|
Subroutine
_build__store: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 55 | 7 | my ($self) = @_; | |||||||||||||||||||||||||||
| 56 | 7 | my %args = ( | |||||||||||||||||||||||||||
| 57 | secret_key => $self->secret_key, | ||||||||||||||||||||||||||||
| 58 | sereal_encoder_options => { snappy => 1, stringify_unknown => 1 }, | ||||||||||||||||||||||||||||
| 59 | sereal_decoder_options => { validate_utf8 => 1 }, | ||||||||||||||||||||||||||||
| 60 | ); | ||||||||||||||||||||||||||||
| 61 | 7 | ▶ | $args{default_duration} = $self->default_duration | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | if $self->has_default_duration; | ||||||||||||||||||||||||||||
| 63 | 7 | return Session::Storage::Secure->new(%args); | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 4 | ▶ | sub _change_id { | ||||||||||||||||||||||||||
|
Subroutine
_change_id: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 67 | # This is a noop with session cookies. | ||||||||||||||||||||||||||||
| 68 | 4 | return; | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 3 | with 'Dancer2::Core::Role::SessionFactory'; | |||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | #--------------------------------------------------------------------------# | ||||||||||||||||||||||||||||
| 74 | # Modified SessionFactory methods | ||||||||||||||||||||||||||||
| 75 | #--------------------------------------------------------------------------# | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | # We don't need to generate an ID. We'll set it during cookie generation | ||||||||||||||||||||||||||||
| 78 | 25 | ▶ | sub generate_id { '' } | ||||||||||||||||||||||||||
|
Subroutine
generate_id: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | # Cookie generation: serialize the session data into the session ID | ||||||||||||||||||||||||||||
| 81 | # right before the cookie is generated | ||||||||||||||||||||||||||||
| 82 | 40 | ▶ | before 'cookie' => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=12.0
| |||||||||||||||||||||||||||||
| 83 | 40 | my ( $self, %params ) = @_; | |||||||||||||||||||||||||||
| 84 | 40 | my $session = $params{session}; | |||||||||||||||||||||||||||
| 85 | 40 | ▶ | return unless ref $session && $session->isa("Dancer2::Core::Session"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $session and $session->isa("Dancer2::Core::Session")
MC/DC0%0/2
ref $session and $session->isa("Dancer2::Core::Session")
ref $session
$session->isa("Dancer2::Core::Session")
Truth table33%1/3
A and B
A= ref $sessionB= $session->isa("Dancer2::Core::Session")
| |||||||||||||||||||||||||||||
| 86 | 40 | $session->id( $self->_freeze( $session->data, $session->expires ) ); | |||||||||||||||||||||||||||
| 87 | 3 | }; | |||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | #--------------------------------------------------------------------------# | ||||||||||||||||||||||||||||
| 90 | # SessionFactory implementation methods | ||||||||||||||||||||||||||||
| 91 | #--------------------------------------------------------------------------# | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | # _retrieve handled by _store | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | # We don't actually flush data; instead we modify cookie generation | ||||||||||||||||||||||||||||
| 96 | 33 | ▶ | sub _flush { return } | ||||||||||||||||||||||||||
|
Subroutine
_flush: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | # We have nothing to destroy, either; cookie expiration is all that matters | ||||||||||||||||||||||||||||
| 99 | 8 | ▶ | sub _destroy { return } | ||||||||||||||||||||||||||
|
Subroutine
_destroy: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | # There is no way to know about existing sessions when cookies | ||||||||||||||||||||||||||||
| 102 | # are used as the store, so we lie and return an empty list. | ||||||||||||||||||||||||||||
| 103 | 0 | ▶ | sub _sessions { return [] } | ||||||||||||||||||||||||||
|
Subroutine
_sessions: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 3 | 1; | |||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | # vim: ts=4 sts=4 sw=4 et: | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | __END__ | ||||||||||||||||||||||||||||