line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Dancer2::Session::CHI; |
2
|
|
|
|
|
|
|
# ABSTRACT: Dancer 2 session storage with CHI backend |
3
|
|
|
|
|
|
|
|
4
|
2
|
|
|
2
|
|
11147
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
62
|
|
5
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
50
|
|
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
11
|
use Moo; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
12
|
|
8
|
2
|
|
|
2
|
|
1885
|
use CHI; |
|
2
|
|
|
|
|
71761
|
|
|
2
|
|
|
|
|
65
|
|
9
|
2
|
|
|
2
|
|
17
|
use Type::Tiny; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
57
|
|
10
|
2
|
|
|
2
|
|
12
|
use Types::Standard qw/ Str ArrayRef InstanceOf HashRef/; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
30
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# |
13
|
|
|
|
|
|
|
# Public attributes |
14
|
|
|
|
|
|
|
# |
15
|
|
|
|
|
|
|
has 'driver' => ( |
16
|
|
|
|
|
|
|
is => 'ro', |
17
|
|
|
|
|
|
|
isa => Str, |
18
|
|
|
|
|
|
|
required => 1, |
19
|
|
|
|
|
|
|
); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
has 'driver_args' => ( |
22
|
|
|
|
|
|
|
is => 'ro', |
23
|
|
|
|
|
|
|
isa => HashRef, |
24
|
|
|
|
|
|
|
required => 0, |
25
|
|
|
|
|
|
|
); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# |
28
|
|
|
|
|
|
|
# Private attributes |
29
|
|
|
|
|
|
|
# |
30
|
|
|
|
|
|
|
has _chi => ( |
31
|
|
|
|
|
|
|
is => 'lazy', |
32
|
|
|
|
|
|
|
isa => InstanceOf ['CHI::Driver'], |
33
|
|
|
|
|
|
|
handles => { |
34
|
|
|
|
|
|
|
_destroy => 'remove', |
35
|
|
|
|
|
|
|
}, |
36
|
|
|
|
|
|
|
); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# Session methods |
39
|
|
|
|
|
|
|
sub _retrieve { |
40
|
7
|
|
|
7
|
|
81076
|
my ($self) = shift; |
41
|
|
|
|
|
|
|
|
42
|
7
|
|
|
|
|
125
|
return $self->_chi->get( @_ ); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub _flush { |
46
|
7
|
|
|
7
|
|
254990
|
my ($self) = shift; |
47
|
|
|
|
|
|
|
|
48
|
7
|
|
|
|
|
140
|
return $self->_chi->set( @_ ); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub _build__chi { |
52
|
1
|
|
|
1
|
|
13
|
my ($self) = @_; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
return CHI->new( |
55
|
|
|
|
|
|
|
driver => $self->driver, |
56
|
1
|
|
|
|
|
5
|
%{ $self->driver_args }, |
|
1
|
|
|
|
|
11
|
|
57
|
|
|
|
|
|
|
); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
around BUILDARGS => sub { |
61
|
|
|
|
|
|
|
my $orig = shift; |
62
|
|
|
|
|
|
|
my $class = shift; |
63
|
|
|
|
|
|
|
my @args = @_; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
my %chi_args = @args; |
66
|
|
|
|
|
|
|
delete $chi_args{ $_ } foreach qw( postponed_hooks log_cb session_dir driver ); |
67
|
|
|
|
|
|
|
push @args, 'driver_args', \%chi_args; |
68
|
|
|
|
|
|
|
return $class->$orig( @args ); |
69
|
|
|
|
|
|
|
}; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# |
72
|
|
|
|
|
|
|
# Role composition |
73
|
|
|
|
|
|
|
# |
74
|
|
|
|
|
|
|
with 'Dancer2::Core::Role::SessionFactory'; |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
0
|
|
0
|
sub _sessions { my $self = shift; return $self->_chi->get_keys; } |
|
0
|
|
|
|
|
0
|
|
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub _change_id { |
79
|
1
|
|
|
1
|
|
633
|
my ( $self, $old_id, $new_id ) = @_; |
80
|
1
|
|
|
|
|
4
|
$self->_flush( $new_id, $self->_retrieve( $old_id ) ); |
81
|
1
|
|
|
|
|
366
|
$self->_destroy( $old_id ); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
1; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
__END__ |