Coverage Summary

# File Coverage

blib/lib/Prancer/Session/Store/Database.pm
Criterion | Covered | Total | %
--- | --- | --- | ---
statement | 6 | 6 | 100.0
branch |  |  | n/a
condition |  |  | n/a
subroutine | 2 | 2 | 100.0
pod |  |  | n/a
total | 8 | 8 | 100.0

line | stmt | bran | cond | sub | pod | time | code
--- | --- | --- | --- | --- | --- | --- | ---
1 |  |  |  |  |  |  | package Prancer::Session::Store::Database;
2 |  |  |  |  |  |  |
3 | 4 |  |  | 4 |  | 3271 | use strict;
| 4 |  |  |  |  | 5 |
| 4 |  |  |  |  | 123 |
4 | 4 |  |  | 4 |  | 12 | use warnings FATAL => 'all';
| 4 |  |  |  |  | 2 |
| 4 |  |  |  |  | 160 |
5 |  |  |  |  |  |  |
6 |  |  |  |  |  |  | 1;
7 |  |  |  |  |  |  |
8 |  |  |  |  |  |  | =head1 NAME
9 |  |  |  |  |  |  |
10 |  |  |  |  |  |  | Prancer::Session::Store::Database
11 |  |  |  |  |  |  |
12 |  |  |  |  |  |  | =head1 SYNOPSIS
13 |  |  |  |  |  |  |
14 |  |  |  |  |  |  | This module implements a session handler by storing sessions in a database. It
15 |  |  |  |  |  |  | uses a separate database connection from the main application to avoid any
16 |  |  |  |  |  |  | issues with transactions. It wraps all changes to the database in transactions
17 |  |  |  |  |  |  | to ensure consistency.
18 |  |  |  |  |  |  |
19 |  |  |  |  |  |  | This configuration expects a database table that looks like this:
20 |  |  |  |  |  |  |
21 |  |  |  |  |  |  | CREATE TABLE sessions (
22 |  |  |  |  |  |  | id CHAR(72) PRIMARY KEY,
23 |  |  |  |  |  |  | data TEXT,
24 |  |  |  |  |  |  | timeout integer DEFAULT date_part('epoch'::text, now()) NOT NULL
25 |  |  |  |  |  |  | );
26 |  |  |  |  |  |  |
27 |  |  |  |  |  |  | Additionally columns may be added as desired.
28 |  |  |  |  |  |  |
29 |  |  |  |  |  |  | To use this session handler, add this to your configuration file:
30 |  |  |  |  |  |  |
31 |  |  |  |  |  |  | session:
32 |  |  |  |  |  |  | store:
33 |  |  |  |  |  |  | driver: Prancer::Session::Store::Database::Driver::DriverName
34 |  |  |  |  |  |  | options:
35 |  |  |  |  |  |  | table: sessions
36 |  |  |  |  |  |  | database: test
37 |  |  |  |  |  |  | username: test
38 |  |  |  |  |  |  | password: test
39 |  |  |  |  |  |  | hostname: localhost
40 |  |  |  |  |  |  | port: 5432
41 |  |  |  |  |  |  | charset: utf8
42 |  |  |  |  |  |  | connection_check_threshold: 10
43 |  |  |  |  |  |  | expiration_timeout: 3600
44 |  |  |  |  |  |  | autopurge: 0
45 |  |  |  |  |  |  |
46 |  |  |  |  |  |  | =head1 OPTIONS
47 |  |  |  |  |  |  |
48 |  |  |  |  |  |  | =over 4
49 |  |  |  |  |  |  |
50 |  |  |  |  |  |  | =item table
51 |  |  |  |  |  |  |
52 |  |  |  |  |  |  | The name of the table in your database to use to store sessions. This name may
53 |  |  |  |  |  |  | include a schema name. Otherwise the default schema of the user will be used.
54 |  |  |  |  |  |  | If this option is not provided the default will be C<sessions>.
55 |  |  |  |  |  |  |
56 |  |  |  |  |  |  | =item database
57 |  |  |  |  |  |  |
58 |  |  |  |  |  |  | B<REQUIRED> The name of the database to connect to.
59 |  |  |  |  |  |  |
60 |  |  |  |  |  |  | =item username
61 |  |  |  |  |  |  |
62 |  |  |  |  |  |  | The username to use when connecting. If this option is not set the default is
63 |  |  |  |  |  |  | the user running the application server.
64 |  |  |  |  |  |  |
65 |  |  |  |  |  |  | =item password
66 |  |  |  |  |  |  |
67 |  |  |  |  |  |  | The password to use when connectin. If this option is not set the default is to
68 |  |  |  |  |  |  | connect with no password.
69 |  |  |  |  |  |  |
70 |  |  |  |  |  |  | =item hostname
71 |  |  |  |  |  |  |
72 |  |  |  |  |  |  | The host name of the database server. If this option is not set the default is
73 |  |  |  |  |  |  | to connect to localhost.
74 |  |  |  |  |  |  |
75 |  |  |  |  |  |  | =item port
76 |  |  |  |  |  |  |
77 |  |  |  |  |  |  | The port number on which the database server is listening. If this option is
78 |  |  |  |  |  |  | not set the default is to connect on the database's default port.
79 |  |  |  |  |  |  |
80 |  |  |  |  |  |  | =item charset
81 |  |  |  |  |  |  |
82 |  |  |  |  |  |  | The character set to connect to the database with. If this is set to "utf8"
83 |  |  |  |  |  |  | then the database connection will attempt to make UTF8 data Just Work if
84 |  |  |  |  |  |  | available.
85 |  |  |  |  |  |  |
86 |  |  |  |  |  |  | =item connection_check_threshold
87 |  |  |  |  |  |  |
88 |  |  |  |  |  |  | This sets the number of seconds that must elapse between calls to get a
89 |  |  |  |  |  |  | database handle before performing a check to ensure that a database connection
90 |  |  |  |  |  |  | still exists and will reconnect if one does not. This handles cases where the
91 |  |  |  |  |  |  | database handle hasn't been used in a while and the underlying connection has
92 |  |  |  |  |  |  | gone away. If this is not set it will default to 30 seconds.
93 |  |  |  |  |  |  |
94 |  |  |  |  |  |  | =item timeout
95 |  |  |  |  |  |  |
96 |  |  |  |  |  |  | This the number of seconds a session should last in the database before it will
97 |  |  |  |  |  |  | be automatically purged. The default is to purge sessions after 1800 seconds.
98 |  |  |  |  |  |  |
99 |  |  |  |  |  |  | =item autopurge
100 |  |  |  |  |  |  |
101 |  |  |  |  |  |  | This flag controls whether sessions will be automatically purged by Prancer.
102 |  |  |  |  |  |  | If set to 1, the default, on 10% of requests to your application, Prancer will
103 |  |  |  |  |  |  | delete from the database any session that has timed out. If set to 0 then
104 |  |  |  |  |  |  | sessions will never be removed from the database. Note that this doesn't
105 |  |  |  |  |  |  | control whether sessions time out, only whether they get removed from the
106 |  |  |  |  |  |  | database.
107 |  |  |  |  |  |  |
108 |  |  |  |  |  |  | =back
109 |  |  |  |  |  |  |
110 |  |  |  |  |  |  | =cut
111 |  |  |  |  |  |  |
112 |  |  |  |  |  |  |