OpenInteract2/SessionManager/SQLite.pm untested

filter: Statementstmt 0.0% 0 / 52 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 93 CC 7 SCAR 19.1
CC
7
Cov
0%
_create_session
12.0
_validate_config
12.0
_get_sqlite_handle
6.0
CRAP 6.8
1 package OpenInteract2::SessionManager::SQLite;
2  
3 # $Id: SQLite.pm,v 1.5 2005/03/18 04:09:51 lachoy Exp $
4  
5 use strict;
6 use base qw( OpenInteract2::SessionManager );
7 use Log::Log4perl qw( get_logger );
8 use OpenInteract2::Constants qw( :log );
9 use OpenInteract2::Context qw( CTX );
10 use OpenInteract2::Exception qw( oi_error );
11  
12 $OpenInteract2::SessionManager::SQLite::VERSION = sprintf("%d.%02d", q$Revision: 1.5 $ =~ /(\d+)\.(\d+)/);
13  
14 my ( $log );
15  
16 sub _create_session {
17 my ( $class, $session_config, $session_id ) = @_;
18 $log ||= get_logger( LOG_SESSION );
19  
20 my $impl_class = $session_config->{impl_class};
21 my %params = ();
22 if ( my $handle = $class->_get_sqlite_handle( $session_config ) ) {
23 $params{Handle} = $handle;
24 }
25 elsif ( my $dsn = $class->_get_sqlite_dsn( $session_config ) ) {
26 $params{DataSource} = "DBI:SQLite:$dsn";
27 }
28 else {
29 oi_error "Insufficient parameters (this should have been caught ",
30 "earlier): no 'Handle' or 'DataSource' defined";
31 }
32 $log->is_debug &&
33 $log->debug( "Trying to fetch SQLite session '$session_id' ",
34 "[DSN: $params{DataSource}] [Impl: $impl_class] ",
35 "[Handle: $params{Handle}]" );
36 my %session = ();
37 tie %session, $impl_class, $session_id, \%params;
38 return \%session;
39 }
40  
41 sub _validate_config {
42 my ( $class, $session_config ) = @_;
43 my @error_msg = ();
44 unless ( $session_config->{impl_class} ) {
45 push @error_msg,
46 join( '', "Cannot use SQLite session storage without the ",
47 "parameter 'session_info.impl_class' set to the",
48 "correct session implementation. (Normally: ",
49 "Apache::Session::SQLite)" );
50 }
51 my $handle = $class->_get_sqlite_handle( $session_config );
52 my $dsn = $class->_get_sqlite_dsn( $session_config );
53 unless ( $handle or $dsn ) {
54 push @error_msg,
55 join( '', "Cannot use SQLite session storage without the ",
56 "parameter 'session_info.params.dbname' set to a ",
57 "valid SQLite file or the 'session_info.datasource' ",
58 "key set to a valid SQLite datasource." );
59 }
60 return @error_msg;
61 }
62  
63 sub _get_sqlite_handle {
64 my ( $class, $session_config ) = @_;
65 my $ds_name = $session_config->{datasource};
66 return undef unless ( $ds_name );
67 return CTX->datasource( $ds_name );
68 }
69  
70 sub _get_sqlite_dsn {
71 my ( $class, $session_config ) = @_;
72 if ( $session_config->{params}{dbname} ) {
73 return "dbname=$session_config->{params}{dbname}";
74 }
75 return undef;
76 }
77  
78 1;
79  
80 __END__