File Coverage

blib/lib/Dancer2/Session/YAML.pm
Criterion Covered Total %
statement 16 16 100.0
branch n/a
condition n/a
subroutine 5 5 100.0
pod n/a
total 21 21 100.0


line stmt bran cond sub pod time code
1             $Dancer2::Session::YAML::VERSION = '0.400000';
2             # ABSTRACT: YAML-file-based session backend for Dancer2
3              
4             use Moo;
5 4     4   2406 use Dancer2::Core::Types;
  4         6873  
  4         26  
6 4     4   2673 use YAML;
  4         9  
  4         37  
7 4     4   34101  
  4         19085  
  4         669  
8             has _suffix => (
9             is => 'ro',
10             isa => Str,
11             default => sub {'.yml'},
12             );
13              
14             with 'Dancer2::Core::Role::SessionFactory::File';
15              
16             my ( $self, $fh, $data ) = @_;
17             print {$fh} YAML::Dump($data);
18 21     21   67 return;
19 21         44 }
  21         118  
20 21         57932  
21             my ( $self, $fh ) = @_;
22             local $YAML::LoadBlessed = 1;
23             return YAML::LoadFile($fh);
24 16     16   51 }
25 16         46  
26 16         78 1;
27              
28              
29             =pod
30              
31             =encoding UTF-8
32              
33             =head1 NAME
34              
35             Dancer2::Session::YAML - YAML-file-based session backend for Dancer2
36              
37             =head1 VERSION
38              
39             version 0.400000
40              
41             =head1 DESCRIPTION
42              
43             This module implements a session engine based on YAML files. Session are stored
44             in a I<session_dir> as YAML files. The idea behind this module was to provide a
45             human-readable session storage for the developer.
46              
47             This backend is intended to be used in development environments, when digging
48             inside a session can be useful.
49              
50             This backend can perfectly be used in production environments, but two things
51             should be kept in mind: The content of the session files is in plain text, and
52             the session files should be purged by a CRON job.
53              
54             =head1 CONFIGURATION
55              
56             The setting B<session> should be set to C<YAML> in order to use this session
57             engine in a Dancer2 application.
58              
59             Files will be stored to the value of the setting C<session_dir>, whose default
60             value is C<appdir/sessions>.
61              
62             Here is an example configuration that use this session engine and stores session
63             files in /tmp/dancer-sessions
64              
65             session: "YAML"
66              
67             engines:
68             session:
69             YAML:
70             session_dir: "/tmp/dancer-sessions"
71             cookie_duration: 3600 # Default cookie timeout in seconds
72              
73             =head1 DEPENDENCY
74              
75             This module depends on L<YAML>.
76              
77             =head1 SEE ALSO
78              
79             See L<Dancer2::Core::Session> for details about session usage in route handlers.
80              
81             =head1 AUTHOR
82              
83             Dancer Core Developers
84              
85             =head1 COPYRIGHT AND LICENSE
86              
87             This software is copyright (c) 2022 by Alexis Sukrieh.
88              
89             This is free software; you can redistribute it and/or modify it under
90             the same terms as the Perl 5 programming language system itself.
91              
92             =cut