Session/Store/MariaDBJSON.pm

filter: Statementstmt 98.2% 57 / 58 Branchbran 92.8% 13 / 14 Conditioncond 58.8% 10 / 17 MC/DCmcdc 27.2% 3 / 11 Subroutinesub 100% 12 / 12 Podpod 0.0% 0 / 6 totaltotal 80.5% 95 / 118 CC 14 SCAR 15.2
CC
14
Cov
90%
connection
9.5
update
3.0
remove
2.3
CRAP 4.6
« Session/_common.pm ↑ Summary Session/Store/DBI.pm »
1 package Web::Session::Store::MariaDBJSON;
2  
3 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 11 ▶use DBI;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 11 ▶use Apache::Session::Store::MySQL;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 11 ▶use Web::Session::Store::DBI;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 # Only id and a_session are written: indexed fields are generated columns
10 11 our @ISA = qw(Apache::Session::Store::MySQL);
11 11 our $VERSION = '1.2.0';
12  
13 # DBD::MariaDB always uses utf8mb4. DBD::mysql only selects the connection
14 # charset from attributes given to connect(): setting mysql_enable_utf8 on an
15 # open handle leaves the default charset of the client library (latin1 on
16 # some builds)
17 13 ▶sub connectAttributes {
Subroutine connectAttributes: called CC=2 SCAR=6.9
Pod undocumented
18 13 my ( $class, $datasource ) = @_;
19 13 my %attr = ( RaiseError => 1, AutoCommit => 1 );
20 13 ▶ $attr{mysql_enable_utf8mb4} = 1 if ( $datasource =~ /^dbi:mysql\b/i );
Branch: 1 branch
BranchTrueFalseTotal
if $datasource =~ /^dbi:mysql\b/i 5 8 13
21 13 return \%attr;
22 }
23  
24 7 ▶sub connection {
Subroutine connection: called CC=9 SCAR=22.5
Pod undocumented
25 7 my ( $self, $session ) = @_;
26 7 my $args = $session->{args};
27 7 Web::Session::Store::DBI::_forgetInheritedHandle($self);
28  
29 # Same as Apache::Session::Store::MySQL, with the right connection
30 # attributes
31 7 ▶ unless ( defined $self->{dbh} or exists $args->{Handle} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"dbh"} or exists $args->{"Handle"}) 6 1 7
Condition66%2/3
defined $self->{"dbh"} or exists $args->{"Handle"}
l!l&&r!l&&!r
016
MC/DC50%1/2
defined $self->{"dbh"} or exists $args->{"Handle"}
defined $self->{"dbh"} exists $args->{"Handle"}
Truth table66%2/3
A or B
A= defined $self->{"dbh"}B= exists $args->{"Handle"}
ABresult
1X1
011
000
32 my $datasource = $args->{DataSource}
33 6 ▶ || $Apache::Session::Store::MySQL::DataSource;
Condition33%1/3
$args->{'DataSource'} || $Apache::Session::Store::MySQL::DataSource
l!l&&r!l&&!r
600
MC/DC0%0/2
$args->{'DataSource'} || $Apache::Session::Store::MySQL::DataSource
$args->{'DataSource'} $Apache::Session::Store::MySQL::DataSource
Truth table33%1/3
A || B
A= $args->{'DataSource'}B= $Apache::Session::Store::MySQL::DataSource
ABresult
1X1
011
000
34 my $username = $args->{UserName}
35 6 ▶ || $Apache::Session::Store::MySQL::UserName;
Condition66%2/3
$args->{'UserName'} || $Apache::Session::Store::MySQL::UserName
l!l&&r!l&&!r
204
MC/DC50%1/2
$args->{'UserName'} || $Apache::Session::Store::MySQL::UserName
$args->{'UserName'} $Apache::Session::Store::MySQL::UserName
Truth table66%2/3
A || B
A= $args->{'UserName'}B= $Apache::Session::Store::MySQL::UserName
ABresult
1X1
011
000
36 my $password = $args->{Password}
37 6 ▶ || $Apache::Session::Store::MySQL::Password;
Condition66%2/3
$args->{'Password'} || $Apache::Session::Store::MySQL::Password
l!l&&r!l&&!r
204
MC/DC50%1/2
$args->{'Password'} || $Apache::Session::Store::MySQL::Password
$args->{'Password'} $Apache::Session::Store::MySQL::Password
Truth table66%2/3
A || B
A= $args->{'Password'}B= $Apache::Session::Store::MySQL::Password
ABresult
1X1
011
000
38 $self->{table_name} =
39 6 ▶ $args->{TableName} || $Apache::Session::Store::DBI::TableName;
Condition66%2/3
$args->{'TableName'} || $Apache::Session::Store::DBI::TableName
l!l&&r!l&&!r
240
MC/DC0%0/2
$args->{'TableName'} || $Apache::Session::Store::DBI::TableName
$args->{'TableName'} $Apache::Session::Store::DBI::TableName
Truth table66%2/3
A || B
A= $args->{'TableName'}B= $Apache::Session::Store::DBI::TableName
ABresult
1X1
011
000
40 6 my $attr = $self->connectAttributes($datasource);
41  
42 # Connection reuse (default), see Web::Session::Store::DBI. This
43 # store doesn't inherit from it: it writes only id and a_session
44 6 ▶ if ( my $dbh =
Branch: 1 branch
BranchTrueFalseTotal
if (my $dbh = Web::Session::Store::DBI::_reusedHandle($self, $args, $datasource, $username, $password, $attr)) 5 1 6
45 Web::Session::Store::DBI::_reusedHandle( $self, $args,
46 $datasource, $username, $password, $attr ) )
47 {
48 5 $self->{dbh} = $dbh;
49 5 $self->{disconnect} = 0;
50 5 return;
51 }
52 $self->{dbh} =
53 1 ▶ DBI->connect( $datasource, $username, $password, $attr )
Condition50%1/2
'DBI'->connect($datasource, $username, $password, $attr) || die($DBI::errstr)
l!l
10
MC/DC0%0/1
'DBI'->connect($datasource, $username, $password, $attr) || die($DBI::errstr)
'DBI'->connect($datasource, $username, $password, $attr)
Truth table50%1/2
A
A= 'DBI'->connect($datasource, $username, $password, $attr)
Aresult
11
00
54 || die $DBI::errstr;
55  
56 # If we open the connection, we close the connection
57 1 $self->{disconnect} = 1;
58 1 return;
59 }
60 1 $self->SUPER::connection($session);
61 }
62  
63 # update() and materialize() of Apache::Session::Store::DBI, keeping the
64 # serialized data that the database holds: update() doesn't rewrite an
65 # unchanged session, as the stores inheriting from Web::Session::Store::DBI
66 # (see "Unchanged sessions are not rewritten" there). Generated columns are
67 # computed from a_session: unchanged too
68 8 ▶sub update {
Subroutine update: called CC=3 SCAR=11.0
Pod undocumented
69 8 my ( $self, $session ) = @_;
70 8 ▶ return 1 if ( Web::Session::Store::DBI::_insertPending( $self, $session ) );
Branch: 1 branch
BranchTrueFalseTotal
if Web::Session::Store::DBI::_insertPending($self, $session) 2 5 7
71 5 ▶ return 1 if ( Web::Session::Store::DBI::_unchanged( $self, $session ) );
Branch: 1 branch
BranchTrueFalseTotal
if Web::Session::Store::DBI::_unchanged($self, $session) 4 1 5
72 1 $self->SUPER::update($session);
73 1 Web::Session::Store::DBI::_checkStored( $self, $session );
74 1 Web::Session::Store::DBI::_remember( $self, $session );
75 1 return 1;
76 }
77  
78 1 ▶sub materialize {
Subroutine materialize: called CC=1 SCAR=0.0
Pod undocumented
79 1 my ( $self, $session ) = @_;
80 1 $self->SUPER::materialize($session);
81 1 Web::Session::Store::DBI::_remember( $self, $session );
82 }
83  
84 # A new session is written once (see "New sessions written once" in
85 # Store/DBI.pm), unless the caller gives its own Handle
86 7 ▶sub insert {
Subroutine insert: called CC=2 SCAR=6.9
Pod undocumented
87 7 my ( $self, $session ) = @_;
88 return $self->SUPER::insert($session)
89 7 ▶ if ( exists $session->{args}->{Handle} );
Branch: 1 branch
BranchTrueFalseTotal
if exists $session->{"args"}{"Handle"} 1 6 7
90 6 $self->connection($session);
91 6 return Web::Session::Store::DBI::_deferInsert( $self, $session );
92 }
93  
94 5 ▶sub _insertNow {
Subroutine _insertNow: called CC=1 SCAR=0.0
95 5 my ( $self, $session ) = @_;
96 5 return $self->SUPER::insert($session);
97 }
98  
99 1 ▶sub remove {
Subroutine remove: called CC=2 SCAR=8.1
Pod undocumented
100 1 my ( $self, $session ) = @_;
101 1 ▶ return 1 if ( Web::Session::Store::DBI::_removePending($self) );
Branch: 1 branch
BranchTrueFalseTotal
if Web::Session::Store::DBI::_removePending($self) 1 0 1
102 0 return $self->SUPER::remove($session);
103 }
104  
105 19 ▶sub DESTROY {
Subroutine DESTROY: called CC=1 SCAR=0.0
106 19 my ($self) = @_;
107 19 Web::Session::Store::DBI::_destroyPending($self);
108 19 $self->SUPER::DESTROY;
109 }
110  
111 11 1;
« Session/_common.pm ↑ Summary Session/Store/DBI.pm »