| 1 | package Dancer2::Session::Simple; | ||||||||||
| 2 | # ABSTRACT: in-memory session backend for Dancer2 | ||||||||||
| 3 | 138 | $Dancer2::Session::Simple::VERSION = '2.3.0'; | |||||||||
| 4 | 138 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 138 | ▶ | use Dancer2::Core::Types; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 138 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 138 | with 'Dancer2::Core::Role::SessionFactory'; | |||||||||
| 9 | |||||||||||
| 10 | # The singleton that contains all the session objects created | ||||||||||
| 11 | 138 | my $SESSIONS = {}; | |||||||||
| 12 | |||||||||||
| 13 | 3 | ▶ | sub _sessions { | ||||||||
|
Subroutine
_sessions: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 3 | my ($self) = @_; | |||||||||
| 15 | 3 | return [ keys %{$SESSIONS} ]; | |||||||||
| 16 | } | ||||||||||
| 17 | |||||||||||
| 18 | 36 | ▶ | sub _retrieve { | ||||||||
|
Subroutine
_retrieve: called CC=2 SCAR=6.9
| |||||||||||
| 19 | 36 | my ( $class, $id ) = @_; | |||||||||
| 20 | 36 | my $s = $SESSIONS->{$id}; | |||||||||
| 21 | |||||||||||
| 22 | 36 | ▶ | croak "Invalid session ID: $id" | ||||||||
|
Branch: 1 branch
| |||||||||||
| 23 | if !defined $s; | ||||||||||
| 24 | |||||||||||
| 25 | 32 | return $s; | |||||||||
| 26 | } | ||||||||||
| 27 | |||||||||||
| 28 | 3 | ▶ | sub _change_id { | ||||||||
|
Subroutine
_change_id: called CC=1 SCAR=0.0
| |||||||||||
| 29 | 3 | my ( $class, $old_id, $new_id ) = @_; | |||||||||
| 30 | |||||||||||
| 31 | 3 | $SESSIONS->{$new_id} = $class->_retrieve($old_id); | |||||||||
| 32 | 3 | delete $SESSIONS->{$old_id}; | |||||||||
| 33 | } | ||||||||||
| 34 | |||||||||||
| 35 | 8 | ▶ | sub _destroy { | ||||||||
|
Subroutine
_destroy: called CC=1 SCAR=0.0
| |||||||||||
| 36 | 8 | my ( $class, $id ) = @_; | |||||||||
| 37 | 8 | delete $SESSIONS->{$id}; | |||||||||
| 38 | } | ||||||||||
| 39 | |||||||||||
| 40 | 10090 | ▶ | sub _flush { | ||||||||
|
Subroutine
_flush: called CC=1 SCAR=0.0
| |||||||||||
| 41 | 10090 | my ( $class, $id, $data ) = @_; | |||||||||
| 42 | 10090 | $SESSIONS->{$id} = $data; | |||||||||
| 43 | } | ||||||||||
| 44 | |||||||||||
| 45 | 138 | 1; | |||||||||
| 46 | |||||||||||
| 47 | __END__ | ||||||||||