File Coverage

blib/lib/Dancer2/Session/Sereal.pm
Criterion Covered Total %
statement 21 35 60.0
branch n/a
condition n/a
subroutine 7 11 63.6
pod n/a
total 28 46 60.8


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