Session/Store/Cassandra.pm

filter: Statementstmt 80.3% 41 / 51 Branchbran 58.3% 7 / 12 Conditioncond 38.4% 5 / 13 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 2 totaltotal 64.5% 60 / 93 CC 12 SCAR 19.0
CC
12
Cov
70%
connection
10.6
materialize
7.0
DESTROY
2.0
CRAP 6.7
« Session/File.pm ↑ Summary Session/Store/MariaDBJSON.pm »
1 package Web::Session::Store::Cassandra;
2  
3 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 5 ▶use Apache::Session::Store::DBI;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶use Web::Session::Store::DBI;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use Web::Session::Store::Cassandra;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 5 our @ISA = qw(Web::Session::Store::DBI);
10 5 our $VERSION = '1.0.0';
11  
12 5 our $DataSource = undef;
13 5 our $UserName = undef;
14 5 our $Password = undef;
15  
16 9 ▶sub connection {
Subroutine connection: called CC=8 SCAR=23.6
Pod undocumented
17 9 my $self = shift;
18 9 my $session = shift;
19  
20 9 $self->_forgetInheritedHandle;
21 9 ▶ return if ( defined $self->{dbh} );
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"dbh"} 0 9 9
22  
23 9 ▶ if ( exists $session->{args}->{Handle} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $session->{"args"}{"Handle"}) 0 9 9
24 0 $self->{dbh} = $session->{args}->{Handle};
25 0 return;
26 }
27  
28 my $datasource = $session->{args}->{DataSource}
29 9 ▶ || $DataSource;
Condition33%1/3
$session->{'args'}{'DataSource'} || $Web::Session::Store::Cassandra::DataSource
l!l&&r!l&&!r
900
MC/DC0%0/2
$session->{'args'}{'DataSource'} || $Web::Session::Store::Cassandra::DataSource
$session->{'args'}{'DataSource'} $Web::Session::Store::Cassandra::DataSource
Truth table33%1/3
A || B
A= $session->{'args'}{'DataSource'}B= $Web::Session::Store::Cassandra::DataSource
ABresult
1X1
011
000
30 my $username = $session->{args}->{UserName}
31 9 ▶ || $UserName;
Condition33%1/3
$session->{'args'}{'UserName'} || $Web::Session::Store::Cassandra::UserName
l!l&&r!l&&!r
009
MC/DC0%0/2
$session->{'args'}{'UserName'} || $Web::Session::Store::Cassandra::UserName
$session->{'args'}{'UserName'} $Web::Session::Store::Cassandra::UserName
Truth table33%1/3
A || B
A= $session->{'args'}{'UserName'}B= $Web::Session::Store::Cassandra::UserName
ABresult
1X1
011
000
32 my $password = $session->{args}->{Password}
33 9 ▶ || $Password;
Condition33%1/3
$session->{'args'}{'Password'} || $Web::Session::Store::Cassandra::Password
l!l&&r!l&&!r
009
MC/DC0%0/2
$session->{'args'}{'Password'} || $Web::Session::Store::Cassandra::Password
$session->{'args'}{'Password'} $Web::Session::Store::Cassandra::Password
Truth table33%1/3
A || B
A= $session->{'args'}{'Password'}B= $Web::Session::Store::Cassandra::Password
ABresult
1X1
011
000
34  
35 9 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (my $dbh = $self->_reusedHandle($session->{"args"}, $datasource, $username, $password, {"RaiseError", 1})) 8 1 9
36 my $dbh = $self->_reusedHandle(
37 $session->{args}, $datasource, $username, $password,
38 { RaiseError => 1 }
39 )
40 )
41 {
42 8 $self->{dbh} = $dbh;
43 8 return;
44 }
45  
46 $self->{dbh} =
47 1 ▶ DBI->connect( $datasource, $username, $password, { RaiseError => 1 } )
Condition50%1/2
'DBI'->connect($datasource, $username, $password, {'RaiseError', 1}) || die($DBI::errstr)
l!l
10
MC/DC0%0/1
'DBI'->connect($datasource, $username, $password, {'RaiseError', 1}) || die($DBI::errstr)
'DBI'->connect($datasource, $username, $password, {'RaiseError', 1})
Truth table50%1/2
A
A= 'DBI'->connect($datasource, $username, $password, {'RaiseError', 1})
Aresult
11
00
48 || die $DBI::errstr;
49  
50 #If we open the connection, we close the connection
51 1 $self->{disconnect} = 1;
52 }
53  
54 1 ▶sub materialize {
Subroutine materialize: called CC=4 SCAR=19.4
Pod undocumented
55 1 my $self = shift;
56 1 my $session = shift;
57  
58 1 $self->connection($session);
59  
60 1 local $self->{dbh}->{RaiseError} = 1;
61 local $self->{dbh}->{LongReadLen} =
62 1 ▶ $session->{args}->{LongReadLen} || 8 * 2**10;
Condition50%1/2
$session->{'args'}{'LongReadLen'} || 8192
l!l
01
MC/DC0%0/1
$session->{'args'}{'LongReadLen'} || 8192
$session->{'args'}{'LongReadLen'}
Truth table50%1/2
A
A= $session->{'args'}{'LongReadLen'}
Aresult
11
00
63  
64 1 ▶ if ( !defined $self->{materialize_sth} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"materialize_sth"}) 1 0 1
65 $self->{materialize_sth} = $self->{dbh}->prepare_cached(
66 1 qq{
67 SELECT a_session FROM sessions WHERE id = ? FOR UPDATE}
68 );
69 }
70  
71 0 $self->{materialize_sth}->bind_param( 1, $session->{data}->{_session_id} );
72 0 $self->{materialize_sth}->execute;
73  
74 0 my $results = $self->{materialize_sth}->fetchrow_arrayref;
75  
76 0 ▶ if ( !( defined $results ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $results) 0 0 0
77 0 die "Object does not exist in the data store";
78 }
79  
80 0 $self->{materialize_sth}->finish;
81  
82 0 $session->{serialized} = $results->[0];
83  
84 # Overrides Web::Session::Store::DBI's materialize(): keep what was read,
85 # see "Unchanged sessions are not rewritten" there
86 0 $self->_remember($session);
87 }
88  
89 8 ▶sub DESTROY {
Subroutine DESTROY: called CC=2 SCAR=6.9
90 8 my $self = shift;
91  
92 8 ▶ if ( $self->{disconnect} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"disconnect"}) 1 7 8
93 1 $self->{dbh}->disconnect;
94 }
95 }
96  
97 5 1;
98  
99 =pod
100  
101 =head1 NAME
102  
103 Web::Session::Store::Cassandra - Store persistent data in a Cassandra database
104  
105 =head1 SYNOPSIS
106  
107 use Web::Session::Store::Cassandra;
108
109 my $store = new Web::Session::Store::Cassandra;
110
111 $store->insert($ref);
112 $store->update($ref);
113 $store->materialize($ref);
114 $store->remove($ref);
115  
116 =head1 DESCRIPTION
117  
118 Web::Session::Store::Cassandra fulfills the storage interface of
119 Apache::Session. Session data is stored in a Cassandra database.
120  
121 =head1 SCHEMA
122  
123 To use this module, you will need at least these columns in a table
124 called 'sessions':
125  
126 id text
127 a_session text
128  
129 To create this schema, you can execute this command using cqlsh:
130  
131 CREATE TABLE sessions (
132 id text PRIMARY KEY,
133 a_session text
134 );
135  
136 =head1 CONFIGURATION
137  
138 The module must know what datasource, username, and password to use when
139 connecting to the database. These values can be set using the options hash
140 (see Apache::Session documentation). The options are DataSource, UserName,
141 and Password.
142  
143 Example:
144  
145 tie %hash, 'Apache::Session::Cassandra', $id, {
146 DataSource => 'dbi:Cassandra:host=localhost;keyspace=llng',
147 UserName => 'database_user',
148 Password => 'K00l'
149 };
150  
151 Instead, you may pass in an already-opened DBI handle to your database.
152  
153 tie %hash, 'Apache::Session::Cassandra', $id, {
154 Handle => $dbh
155 };
156  
157 =head1 SEE ALSO
158  
159 L<Apache::Session>, L<Apache::Session::Store::DBI>
160  
161 =head1 COPYRIGHT AND LICENSE
162  
163 =encoding utf8
164  
165 Copyright (C):
166  
167 =over
168  
169 =item 2009-2026 by Xavier Guimard
170  
171 =item 2013-2025 by Clément Oudot
172  
173 =item 2019-2025 by Maxime Besson
174  
175 =item 2013-2025 by Worteks
176  
177 =item 2023-2026 by Linagora
178  
179 =back
180  
181 This library is free software; you can redistribute it and/or modify
182 it under the same terms as Perl itself, either Perl version 5.10.1 or,
183 at your option, any later version of Perl 5 you may have available.
184  
185 =cut
« Session/File.pm ↑ Summary Session/Store/MariaDBJSON.pm »