| 1 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | package Dancer::Session::Memcached::Fast; | ||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | # ABSTRACT: Cache::Memcached::Fast based session backend for Dancer | ||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 1 | our $VERSION = '0.001'; # VERSION | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use mro; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use Cache::Memcached::Fast; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use CBOR::XS qw(encode_cbor decode_cbor); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use Dancer::Config qw(setting); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use Dancer qw(config); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use parent 'Dancer::Session::Abstract'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 1 | my $setting_prefix = 'session_memcached_fast_'; | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | sub _setting { | ||||||||||||||||||||||||||||
| 21 | 0 | ▶ | setting( $setting_prefix . shift(), @_ ); | ||||||||||||||||||||||||||
|
Subroutine
_setting: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | sub init { | ||||||||||||||||||||||||||||
| 25 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
init: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 0 | $self->next::method(@_); | |||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 0 | my $servers = _setting('servers'); | |||||||||||||||||||||||||||
| 30 | 0 | ▶ | croak "The setting session_memcached_servers must be defined" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | unless defined $servers; | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 0 | $servers = [ split /,/, $servers ]; | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 0 | $self->{cmf} = Cache::Memcached::Fast->new( | |||||||||||||||||||||||||||
| 36 | { | ||||||||||||||||||||||||||||
| 37 | servers => $servers, | ||||||||||||||||||||||||||||
| 38 | check_args => '', | ||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | ); | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 0 | $self; | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | sub _engine { | ||||||||||||||||||||||||||||
| 46 | 0 | ▶ | Dancer::engine('session'); | ||||||||||||||||||||||||||
|
Subroutine
_engine: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | sub _mkns { | ||||||||||||||||||||||||||||
| 50 | 0 | ▶ | my $id = shift; | ||||||||||||||||||||||||||
|
Subroutine
_mkns: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 51 | 0 | ▶ | my $ns = _setting('namespace') || config->{appname}; | ||||||||||||||||||||||||||
|
Condition0%0/3
_setting('namespace') || config()->{'appname'}
MC/DC0%0/2
_setting('namespace') || config()->{'appname'}
_setting('namespace')
config()->{'appname'}
Truth table0%0/3
A || B
A= _setting('namespace')B= config()->{'appname'}
| |||||||||||||||||||||||||||||
| 52 | 0 | return "$ns#$id"; | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | sub _boot { | ||||||||||||||||||||||||||||
| 56 | 0 | ▶ | my ( $class, %config ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_boot: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 57 | 0 | my $engine = _engine; | |||||||||||||||||||||||||||
| 58 | bless { | ||||||||||||||||||||||||||||
| 59 | id => undef, | ||||||||||||||||||||||||||||
| 60 | cmf => $engine->{cmf}, | ||||||||||||||||||||||||||||
| 61 | 0 | %config | |||||||||||||||||||||||||||
| 62 | } => $class; | ||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | sub _set_expire { | ||||||||||||||||||||||||||||
| 66 | 0 | ▶ | my ( $self, $expire ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_set_expire: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 67 | 0 | ▶ | $expire //= setting('session_expires'); | ||||||||||||||||||||||||||
|
Condition0%0/3
$expire //= setting("session_expires")
MC/DC0%0/2
$expire //= setting("session_expires")
$expire
setting("session_expires")
Truth table0%0/3
A //= B
A= $expireB= setting("session_expires")
| |||||||||||||||||||||||||||||
| 68 | 0 | ▶ | if ($expire) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | 0 | ▶ | if ( $expire !~ m{^\d+$} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | 0 | $expire = Dancer::Cookie::_parse_duration($expire); | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | 0 | $expire -= time; | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | else { | ||||||||||||||||||||||||||||
| 75 | 0 | $expire = undef; | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | 0 | $self->{cmf}->set( '' => time, $expire ); | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | sub create { | ||||||||||||||||||||||||||||
| 81 | 0 | ▶ | my ($class) = @_; | ||||||||||||||||||||||||||
|
Subroutine
create: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 82 | 0 | my $self = $class->_boot( id => $class->build_id ); | |||||||||||||||||||||||||||
| 83 | 0 | $self->{cmf}->namespace( _mkns( $self->id ) ); | |||||||||||||||||||||||||||
| 84 | 0 | $self->_set_expire; | |||||||||||||||||||||||||||
| 85 | 0 | $self; | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | sub retrieve { | ||||||||||||||||||||||||||||
| 89 | 0 | ▶ | my ( $class, $id ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
retrieve: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 90 | 0 | my $self = $class->_boot( id => $id ); | |||||||||||||||||||||||||||
| 91 | 0 | $self->{cmf}->namespace( _mkns( $self->id ) ); | |||||||||||||||||||||||||||
| 92 | 0 | my $time = $self->{cmf}->get(''); | |||||||||||||||||||||||||||
| 93 | 0 | ▶ | return unless defined $time and $time =~ m{^\d+$}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $time and $time =~ /^\d+$/
MC/DC0%0/2
defined $time and $time =~ /^\d+$/
defined $time
$time =~ /^\d+$/
Truth table0%0/3
A and B
A= defined $timeB= $time =~ /^\d+$/
| |||||||||||||||||||||||||||||
| 94 | 0 | $self->_set_expire; | |||||||||||||||||||||||||||
| 95 | 0 | $self; | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | sub get_value { | ||||||||||||||||||||||||||||
| 99 | 0 | ▶ | my ( $self, $key ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
get_value: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 100 | 0 | my $value = $self->{cmf}->get($key); | |||||||||||||||||||||||||||
| 101 | 0 | ▶ | return unless defined $value; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | 0 | decode_cbor $value; | |||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | sub set_value { | ||||||||||||||||||||||||||||
| 106 | 0 | ▶ | my ( $self, $key, $value ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
set_value: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 107 | 0 | $self->{cmf}->set( $key => encode_cbor $value); | |||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | sub destroy { | ||||||||||||||||||||||||||||
| 111 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
destroy: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 112 | 0 | $self->{cmf}->flush_all; | |||||||||||||||||||||||||||
| 113 | 0 | undef; | |||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | sub flush { | ||||||||||||||||||||||||||||
| 117 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
flush: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 118 | 0 | $self->{cmf}->nowait_push; | |||||||||||||||||||||||||||
| 119 | 0 | $self; | |||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 1 | 1; | |||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | __END__ | ||||||||||||||||||||||||||||