Session/Store/Cassandra.pm

filter: Statementstmt 84.3% 43 / 51 Branchbran 66.6% 8 / 12 Conditioncond 38.4% 5 / 13 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 2 totaltotal 68.0% 64 / 94 CC 12 SCAR 17.5
CC
12
Cov
74%
connection
9.0
materialize
7.0
DESTROY
2.0
CRAP 5.7
« Session/File.pm ↑ Summary Session/Store/SQLite.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.2.0';
11  
12 5 our $DataSource = undef;
13 5 our $UserName = undef;
14 5 our $Password = undef;
15  
16 10 ▶sub connection {
Subroutine connection: called CC=8 SCAR=22.0
Pod undocumented
17 10 my $self = shift;
18 10 my $session = shift;
19  
20 10 $self->_forgetInheritedHandle;
21 10 ▶ return if ( defined $self->{dbh} );
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"dbh"} 0 10 10
22  
23 10 ▶ if ( exists $session->{args}->{Handle} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $session->{"args"}{"Handle"}) 1 9 10
24 1 $self->{dbh} = $session->{args}->{Handle};
25 1 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 # A CQL UPDATE is an upsert: the row exists after it, also when the session
55 # was deleted meanwhile. And DBD::Cassandra counts the rows returned, 0 for an
56 # UPDATE: there is nothing to check
57 1 ▶sub _checkStored { }
Subroutine _checkStored: called CC=1 SCAR=0.0
58  
59 1 ▶sub materialize {
Subroutine materialize: called CC=4 SCAR=19.4
Pod undocumented
60 1 my $self = shift;
61 1 my $session = shift;
62  
63 1 $self->connection($session);
64  
65 1 local $self->{dbh}->{RaiseError} = 1;
66 local $self->{dbh}->{LongReadLen} =
67 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
68  
69 1 ▶ if ( !defined $self->{materialize_sth} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"materialize_sth"}) 1 0 1
70 $self->{materialize_sth} = $self->{dbh}->prepare_cached(
71 1 qq{
72 SELECT a_session FROM sessions WHERE id = ? FOR UPDATE}
73 );
74 }
75  
76 0 $self->{materialize_sth}->bind_param( 1, $session->{data}->{_session_id} );
77 0 $self->{materialize_sth}->execute;
78  
79 0 my $results = $self->{materialize_sth}->fetchrow_arrayref;
80  
81 0 ▶ if ( !( defined $results ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $results) 0 0 0
82 0 die "Object does not exist in the data store";
83 }
84  
85 0 $self->{materialize_sth}->finish;
86  
87 0 $session->{serialized} = $results->[0];
88  
89 # Overrides Web::Session::Store::DBI's materialize(): keep what was read,
90 # see "Unchanged sessions are not rewritten" there
91 0 $self->_remember($session);
92 }
93  
94 9 ▶sub DESTROY {
Subroutine DESTROY: called CC=2 SCAR=6.9
95 9 my $self = shift;
96  
97 9 ▶ if ( $self->{disconnect} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"disconnect"}) 1 8 9
98 1 $self->{dbh}->disconnect;
99 }
100 }
101  
102 5 1;
103  
104 =pod
105  
106 =head1 NAME
107  
108 Web::Session::Store::Cassandra - Store persistent data in a Cassandra database
109  
110 =head1 SYNOPSIS
111  
112 use Web::Session::Store::Cassandra;
113  
114 my $store = new Web::Session::Store::Cassandra;
115  
116 $store->insert($ref);
117 $store->update($ref);
118 $store->materialize($ref);
119 $store->remove($ref);
120  
121 =head1 DESCRIPTION
122  
123 Web::Session::Store::Cassandra fulfills the storage interface of
124 Apache::Session. Session data is stored in a Cassandra database.
125  
126 =head1 SCHEMA
127  
128 To use this module, you will need at least these columns in a table
129 called 'sessions':
130  
131 id text
132 a_session text
133  
134 To create this schema, you can execute this command using cqlsh:
135  
136 CREATE TABLE sessions (
137 id text PRIMARY KEY,
138 a_session text
139 );
140  
141 =head1 CONFIGURATION
142  
143 The module must know what datasource, username, and password to use when
144 connecting to the database. These values can be set using the options hash
145 (see Apache::Session documentation). The options are DataSource, UserName,
146 and Password.
147  
148 Example:
149  
150 tie %hash, 'Apache::Session::Cassandra', $id, {
151 DataSource => 'dbi:Cassandra:host=localhost;keyspace=llng',
152 UserName => 'database_user',
153 Password => 'K00l'
154 };
155  
156 Instead, you may pass in an already-opened DBI handle to your database.
157  
158 tie %hash, 'Apache::Session::Cassandra', $id, {
159 Handle => $dbh
160 };
161  
162 =head1 SEE ALSO
163  
164 L<Apache::Session>, L<Apache::Session::Store::DBI>
165  
166 =head1 COPYRIGHT AND LICENSE
167  
168 =encoding utf8
169  
170 Copyright (C):
171  
172 =over
173  
174 =item 2009-2026 by Xavier Guimard
175  
176 =item 2013-2025 by Clément Oudot
177  
178 =item 2019-2025 by Maxime Besson
179  
180 =item 2013-2025 by Worteks
181  
182 =item 2023-2026 by Linagora
183  
184 =back
185  
186 This library is free software; you can redistribute it and/or modify
187 it under the same terms as Perl itself, either Perl version 5.10.1 or,
188 at your option, any later version of Perl 5 you may have available.
189  
190 =cut
« Session/File.pm ↑ Summary Session/Store/SQLite.pm »