| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
1
|
|
|
1
|
|
8103
|
use 5.008001; |
|
|
1
|
|
|
|
|
5
|
|
|
2
|
1
|
|
|
1
|
|
3
|
use strict; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
17
|
|
|
3
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
50
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Dancer2::Session::Sereal; |
|
6
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:YANICK'; |
|
7
|
|
|
|
|
|
|
# ABSTRACT: Dancer 2 session storage in files with Sereal |
|
8
|
|
|
|
|
|
|
# VERSION |
|
9
|
|
|
|
|
|
|
$Dancer2::Session::Sereal::VERSION = '0.002'; |
|
10
|
1
|
|
|
1
|
|
4
|
use Moo; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
7
|
|
|
11
|
1
|
|
|
1
|
|
218
|
use Dancer2::Core::Types; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
315
|
|
|
12
|
1
|
|
|
1
|
|
4
|
use Sereal::Encoder; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
28
|
|
|
13
|
1
|
|
|
1
|
|
3
|
use Sereal::Decoder; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
223
|
|
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
#--------------------------------------------------------------------------# |
|
16
|
|
|
|
|
|
|
# Attributes |
|
17
|
|
|
|
|
|
|
#--------------------------------------------------------------------------# |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
has _suffix => ( |
|
20
|
|
|
|
|
|
|
is => 'ro', |
|
21
|
|
|
|
|
|
|
isa => Str, |
|
22
|
|
|
|
|
|
|
default => sub { ".srl" }, |
|
23
|
|
|
|
|
|
|
); |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
has _encoder => ( |
|
26
|
|
|
|
|
|
|
is => 'lazy', |
|
27
|
|
|
|
|
|
|
isa => InstanceOf ['Sereal::Encoder'], |
|
28
|
|
|
|
|
|
|
handles => { '_freeze' => 'encode' }, |
|
29
|
|
|
|
|
|
|
); |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub _build__encoder { |
|
32
|
1
|
|
|
1
|
|
664
|
my ($self) = @_; |
|
33
|
1
|
|
|
|
|
33
|
return Sereal::Encoder->new( |
|
34
|
|
|
|
|
|
|
{ |
|
35
|
|
|
|
|
|
|
snappy => 1, |
|
36
|
|
|
|
|
|
|
croak_on_bless => 1, |
|
37
|
|
|
|
|
|
|
} |
|
38
|
|
|
|
|
|
|
); |
|
39
|
|
|
|
|
|
|
} |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
has _decoder => ( |
|
42
|
|
|
|
|
|
|
is => 'lazy', |
|
43
|
|
|
|
|
|
|
isa => InstanceOf ['Sereal::Decoder'], |
|
44
|
|
|
|
|
|
|
handles => { '_thaw' => 'decode' }, |
|
45
|
|
|
|
|
|
|
); |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub _build__decoder { |
|
48
|
1
|
|
|
1
|
|
722
|
my ($self) = @_; |
|
49
|
1
|
|
|
|
|
26
|
return Sereal::Decoder->new( |
|
50
|
|
|
|
|
|
|
{ |
|
51
|
|
|
|
|
|
|
refuse_objects => 1, |
|
52
|
|
|
|
|
|
|
validate_utf8 => 1, |
|
53
|
|
|
|
|
|
|
} |
|
54
|
|
|
|
|
|
|
); |
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
#--------------------------------------------------------------------------# |
|
58
|
|
|
|
|
|
|
# Role composition |
|
59
|
|
|
|
|
|
|
#--------------------------------------------------------------------------# |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
with 'Dancer2::Core::Role::SessionFactory::File'; |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub _freeze_to_handle { |
|
64
|
6
|
|
|
6
|
|
108366
|
my ($self, $fh, $data) = @_; |
|
65
|
6
|
|
|
|
|
30
|
binmode $fh; |
|
66
|
6
|
|
|
|
|
8
|
print {$fh} $self->_freeze($data); |
|
|
6
|
|
|
|
|
139
|
|
|
67
|
6
|
|
|
|
|
322
|
return; |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub _thaw_from_handle { |
|
71
|
5
|
|
|
5
|
|
71070
|
my ($self, $fh) = @_; |
|
72
|
5
|
|
|
|
|
16
|
binmode($fh); |
|
73
|
5
|
|
|
|
|
9
|
return $self->_thaw( do { local $/; <$fh> } ); |
|
|
5
|
|
|
|
|
20
|
|
|
|
5
|
|
|
|
|
213
|
|
|
74
|
|
|
|
|
|
|
} |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
1; |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=pod |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=encoding UTF-8 |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 NAME |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Dancer2::Session::Sereal - Dancer 2 session storage in files with Sereal |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 VERSION |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
version 0.002 |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
This module implements Dancer 2 session engine based on L files. |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
This backend can be used in single-machine production environments, but two |
|
95
|
|
|
|
|
|
|
things should be kept in mind: The content of the session files is not |
|
96
|
|
|
|
|
|
|
encrypted or protected in anyway and old session files should be purged by a |
|
97
|
|
|
|
|
|
|
CRON job. |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 CONFIGURATION |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
The setting B should be set to C in order to use this session |
|
102
|
|
|
|
|
|
|
engine in a Dancer2 application. |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
Files will be stored to the value of the setting C, whose default |
|
105
|
|
|
|
|
|
|
value is C. |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
Here is an example configuration that use this session engine and stores session |
|
108
|
|
|
|
|
|
|
files in /tmp/dancer-sessions |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
session: "Sereal" |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
engines: |
|
113
|
|
|
|
|
|
|
session: |
|
114
|
|
|
|
|
|
|
Sereal: |
|
115
|
|
|
|
|
|
|
session_dir: "/tmp/dancer-sessions" |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head1 AUTHOR |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
David Golden |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
This software is Copyright (c) 2013 by David Golden. |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
This is free software, licensed under: |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
The Apache License, Version 2.0, January 2004 |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=cut |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
__END__ |