line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
37962
|
use 5.008001; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
67
|
|
2
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
78
|
|
3
|
1
|
|
|
1
|
|
13
|
use warnings; |
|
1
|
|
|
|
|
9
|
|
|
1
|
|
|
|
|
127
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Dancer2::Session::JSON; |
6
|
|
|
|
|
|
|
# ABSTRACT: Dancer 2 session storage in files with JSON |
7
|
|
|
|
|
|
|
our $VERSION = '0.001'; # VERSION |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
16
|
use Moo; |
|
1
|
|
|
|
|
9
|
|
|
1
|
|
|
|
|
49
|
|
10
|
1
|
|
|
1
|
|
669
|
use Dancer2::Core::Types; |
|
1
|
|
|
|
|
11
|
|
|
1
|
|
|
|
|
1083
|
|
11
|
1
|
|
|
1
|
|
24
|
use JSON -convert_blessed_universally; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
57
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
#--------------------------------------------------------------------------# |
14
|
|
|
|
|
|
|
# Attributes |
15
|
|
|
|
|
|
|
#--------------------------------------------------------------------------# |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
has _suffix => ( |
18
|
|
|
|
|
|
|
is => 'ro', |
19
|
|
|
|
|
|
|
isa => Str, |
20
|
|
|
|
|
|
|
default => sub { ".json" }, |
21
|
|
|
|
|
|
|
); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
has _encoder => ( |
24
|
|
|
|
|
|
|
is => 'lazy', |
25
|
|
|
|
|
|
|
isa => InstanceOf ['JSON'], |
26
|
|
|
|
|
|
|
handles => { |
27
|
|
|
|
|
|
|
'_freeze' => 'encode', |
28
|
|
|
|
|
|
|
'_thaw' => 'decode' |
29
|
|
|
|
|
|
|
}, |
30
|
|
|
|
|
|
|
); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub _build__encoder { |
33
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
34
|
0
|
|
|
|
|
|
return JSON->new->allow_blessed->convert_blessed; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
#--------------------------------------------------------------------------# |
38
|
|
|
|
|
|
|
# Role composition |
39
|
|
|
|
|
|
|
#--------------------------------------------------------------------------# |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
with 'Dancer2::Core::Role::SessionFactory::File'; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub _freeze_to_handle { |
44
|
0
|
|
|
0
|
|
|
my ( $self, $fh, $data ) = @_; |
45
|
0
|
|
|
|
|
|
binmode $fh; |
46
|
0
|
|
|
|
|
|
print {$fh} $self->_freeze($data); |
|
0
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
return; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub _thaw_from_handle { |
51
|
0
|
|
|
0
|
|
|
my ( $self, $fh ) = @_; |
52
|
0
|
|
|
|
|
|
binmode($fh); |
53
|
|
|
|
|
|
|
return $self->_thaw( |
54
|
0
|
|
|
|
|
|
do { local $/; <$fh> } |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
1; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=pod |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head1 NAME |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
Dancer2::Session::JSON - Dancer 2 session storage in files with JSON |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head1 VERSION |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
version 0.001 |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head1 DESCRIPTION |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
This module implements Dancer 2 session engine based on L files. |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
This backend can be used in single-machine production environments, but two |
75
|
|
|
|
|
|
|
things should be kept in mind: The content of the session files is not |
76
|
|
|
|
|
|
|
encrypted or protected in anyway and old session files should be purged by a |
77
|
|
|
|
|
|
|
CRON job. |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 CONFIGURATION |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
The setting B should be set to C in order to use this session |
82
|
|
|
|
|
|
|
engine in a Dancer2 application. |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Files will be stored to the value of the setting C, whose default |
85
|
|
|
|
|
|
|
value is C. |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
Here is an example configuration that use this session engine and stores session |
88
|
|
|
|
|
|
|
files in /tmp/dancer-sessions |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
session: "JSON" |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
engines: |
93
|
|
|
|
|
|
|
session: |
94
|
|
|
|
|
|
|
JSON: |
95
|
|
|
|
|
|
|
session_dir: "/tmp/dancer-sessions" |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=for :stopwords cpan testmatrix url annocpan anno bugtracker rt cpants kwalitee diff irc mailto metadata placeholders metacpan |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 SUPPORT |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head2 Bugs / Feature Requests |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
Please report any bugs or feature requests through the issue tracker |
104
|
|
|
|
|
|
|
at L. |
105
|
|
|
|
|
|
|
You will be notified automatically of any progress on your issue. |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head2 Source Code |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
This is open source software. The code repository is available for |
110
|
|
|
|
|
|
|
public review and contribution under the terms of the license. |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
L |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
git clone git://github.com/dagolden/dancer2-session-json.git |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head1 AUTHOR |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
David Golden |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
This software is Copyright (c) 2013 by David Golden. |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
This is free software, licensed under: |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
The Apache License, Version 2.0, January 2004 |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=cut |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
__END__ |