| 1 | ############################################################################# | ||
| 2 | # | ||
| 3 | # Web::Session::SQLite | ||
| 4 | # Apache persistent user sessions in a SQLite database | ||
| 5 | # Copyright(c) 2013-2017 Xavier Guimard <x.guimard@free.fr> | ||
| 6 | # Inspired by Apache::Session::Postgres | ||
| 7 | # (copyright(c) 1998, 1999, 2000 Jeffrey William Baker (jwbaker@acm.org)) | ||
| 8 | # Distribute under the Perl License | ||
| 9 | # | ||
| 10 | ############################################################################ | ||
| 11 | |||
| 12 | package Web::Session::SQLite; | ||
| 13 | |||
| 14 | 13 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 15 | |||
| 16 | 13 | ▶ | use Apache::Session; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 17 | 13 | ▶ | use Apache::Session::Lock::Null; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 18 | 13 | ▶ | use Web::Session::Store::SQLite; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 19 | 13 | ▶ | use Web::Session::Generate::SHA256; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 20 | 13 | ▶ | use Web::Session::Serialize::JSON; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 21 | 13 | ▶ | use Web::Session::DBI; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 22 | |||
| 23 | 13 | our $VERSION = '1.0.0'; | |
| 24 | 13 | our @ISA = qw(Web::Session::DBI Apache::Session); | |
| 25 | |||
| 26 | 307 | ▶ | sub populate { |
|
Subroutine
populate: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 27 | 307 | my $self = shift; | |
| 28 | |||
| 29 | $self->{object_store} = | ||
| 30 | 307 | new Web::Session::Store::SQLite $self; | |
| 31 | 307 | $self->{lock_manager} = new Apache::Session::Lock::Null $self; | |
| 32 | 307 | $self->{generate} = \&Web::Session::Generate::SHA256::generate; | |
| 33 | 307 | $self->{validate} = \&Web::Session::Generate::SHA256::validate; | |
| 34 | 307 | $self->{serialize} = \&Web::Session::Serialize::JSON::serialize; | |
| 35 | 307 | $self->{unserialize} = \&Web::Session::Serialize::JSON::unserialize; | |
| 36 | |||
| 37 | 307 | return $self; | |
| 38 | } | ||
| 39 | |||
| 40 | 13 | 1; | |
| 41 | |||
| 42 | =pod | ||
| 43 | |||
| 44 | =head1 NAME | ||
| 45 | |||
| 46 | Web::Session::SQLite - An implementation of Apache::Session | ||
| 47 | |||
| 48 | =head1 SYNOPSIS | ||
| 49 | |||
| 50 | use Web::Session::SQLite; | ||
| 51 | |||
| 52 | #if you want Apache::Session to open new DB handles: | ||
| 53 | |||
| 54 | tie %hash, 'Web::Session::SQLite', $id, { | ||
| 55 | DataSource => 'dbi:Pg:dbname=sessions', | ||
| 56 | UserName => $db_user, | ||
| 57 | Password => $db_pass, | ||
| 58 | Commit => 1 | ||
| 59 | }; | ||
| 60 | |||
| 61 | #or, if your handles are already opened: | ||
| 62 | |||
| 63 | tie %hash, 'Web::Session::SQLite', $id, { | ||
| 64 | Handle => $dbh, | ||
| 65 | Commit => 1 | ||
| 66 | }; | ||
| 67 | |||
| 68 | L<Web::Session> function are also available | ||
| 69 | |||
| 70 | =head1 DESCRIPTION | ||
| 71 | |||
| 72 | This module is an implementation of Apache::Session. It uses the SQLite | ||
| 73 | backing store and no locking. See the example, and the documentation for | ||
| 74 | Web::Session::Store::SQLite for more details. | ||
| 75 | |||
| 76 | =head1 USAGE | ||
| 77 | |||
| 78 | The special Apache::Session argument for this module is Commit. You MUST | ||
| 79 | provide the Commit argument, which instructs this module to either commit | ||
| 80 | the transaction when it is finished, or to simply do nothing. This feature | ||
| 81 | is provided so that this module will not have adverse interactions with your | ||
| 82 | local transaction policy, nor your local database handle caching policy. The | ||
| 83 | argument is mandatory in order to make you think about this problem. | ||
| 84 | |||
| 85 | =head2 searchLt() and searchGt() | ||
| 86 | |||
| 87 | searchLt() and searchGt() take the same arguments and return the same data as | ||
| 88 | searchOn(): sessions whose field is lower (or greater) than the given value, | ||
| 89 | which is excluded. The value must be a number (C<12>, C<-12> or C<12.5>): | ||
| 90 | otherwise nothing is returned and an error is printed on STDERR. Spaces | ||
| 91 | around the value are ignored. | ||
| 92 | |||
| 93 | Fields listed in C<Index> are compared in SQL as integers | ||
| 94 | (C<cast(field as integer)>), other fields in Perl after reading all sessions. | ||
| 95 | Both compare a non-numeric value as 0, or as its numeric prefix, but SQL keeps | ||
| 96 | only an integer prefix: C<12.7> is 12 and C<1e3> is 1 in SQL, whereas Perl | ||
| 97 | compares 12.7 and 1000. Store integers in indexed fields to get the same | ||
| 98 | results. | ||
| 99 | |||
| 100 | Sessions without the field are never returned, whereas the Perl fallback of | ||
| 101 | Lemonldap::NG compares a missing field as 0. | ||
| 102 | |||
| 103 | =head1 AUTHOR | ||
| 104 | |||
| 105 | This module was written by Xavier Guimard <x.guimard@free.fr> using | ||
| 106 | Apache::Session::Postgres from Jeffrey William Baker as example. | ||
| 107 | |||
| 108 | =head2 Persistent connection | ||
| 109 | |||
| 110 | The database connection is kept open between sessions. Set | ||
| 111 | C<noreuse =E<gt> 1> to open and close one for each session, see | ||
| 112 | L<Web::Session/"PERSISTENT DATABASE CONNECTIONS">. | ||
| 113 | |||
| 114 | =head1 SEE ALSO | ||
| 115 | |||
| 116 | L<Web::Session> | ||