File Coverage

blib/lib/Prancer/Session/Store/Database/Driver/Pg.pm
Criterion Covered Total %
statement 21 43 48.8
branch 0 8 0.0
condition 0 3 0.0
subroutine 7 10 70.0
pod 1 1 100.0
total 29 65 44.6


line stmt bran cond sub pod time code
1             package Prancer::Session::Store::Database::Driver::Pg;
2              
3 1     1   689 use strict;
  1         1  
  1         31  
4 1     1   8 use warnings FATAL => 'all';
  1         2  
  1         30  
5              
6 1     1   4 use version;
  1         2  
  1         3  
7             our $VERSION = '1.01';
8              
9 1     1   59 use Prancer::Session::Store::Database::Driver;
  1         2  
  1         31  
10 1     1   5 use parent qw(Prancer::Session::Store::Database::Driver);
  1         1  
  1         3  
11              
12 1     1   48 use Try::Tiny;
  1         1  
  1         51  
13 1     1   5 use Carp;
  1         1  
  1         287  
14              
15             # even though this *should* work automatically, it was not
16             our @CARP_NOT = qw(Prancer Try::Tiny);
17              
18             sub new {
19 0     0 1   my $class = shift;
20 0           my $self = bless($class->SUPER::new(@_), $class);
21              
22             try {
23 0     0     require DBD::Pg;
24             } catch {
25 0 0   0     my $error = (defined($_) ? $_ : "unknown");
26 0           croak "could not initialize session handler: could not load DBD::Pg: ${error}";
27 0           };
28              
29 0           my $database = $self->{'_database'};
30 0           my $username = $self->{'_username'};
31 0           my $password = $self->{'_password'};
32 0           my $hostname = $self->{'_hostname'};
33 0           my $port = $self->{'_port'};
34 0           my $charset = $self->{'_charset'};
35 0           my $table = $self->{'_table'};
36              
37 0           my $dsn = "dbi:Pg:dbname=${database}";
38 0 0         $dsn .= ";host=${hostname}" if defined($hostname);
39 0 0         $dsn .= ";port=${port}" if defined($port);
40              
41 0           my $params = {
42             'AutoCommit' => 0,
43             'RaiseError' => 1,
44             'PrintError' => 0,
45             };
46 0 0 0       if ($charset && $charset =~ /^utf8$/xi) {
47 0           $params->{'pg_enable_utf8'} = 1;
48             }
49              
50             # merge in any additional dsn_params
51 0           $params = $self->_merge($params, $self->{'_dsn_extra'});
52              
53 0           $self->{'_dsn'} = [ $dsn, $username, $password, $params ];
54 0           return $self;
55             }
56              
57             1;