File Coverage

blib/lib/Prancer/Plugin/Database/Driver/SQLite.pm
Criterion Covered Total %
statement 21 38 55.2
branch 0 8 0.0
condition 0 3 0.0
subroutine 7 10 70.0
pod 0 1 0.0
total 28 60 46.6


line stmt bran cond sub pod time code
1             package Prancer::Plugin::Database::Driver::SQLite;
2              
3 1     1   805 use strict;
  1         1  
  1         33  
4 1     1   4 use warnings FATAL => 'all';
  1         1  
  1         29  
5              
6 1     1   3 use version;
  1         1  
  1         4  
7             our $VERSION = '1.04';
8              
9 1     1   60 use Prancer::Plugin::Database::Driver;
  1         1  
  1         20  
10 1     1   3 use parent qw(Prancer::Plugin::Database::Driver);
  1         1  
  1         7  
11              
12 1     1   44 use Try::Tiny;
  1         2  
  1         45  
13 1     1   4 use Carp;
  1         1  
  1         291  
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 0   my $class = shift;
20 0           my $self = bless($class->SUPER::new(@_), $class);
21              
22             try {
23 0     0     require DBD::SQLite;
24             } catch {
25 0 0   0     my $error = (defined($_) ? $_ : "unknown");
26 0           croak "could not initialize database connection '${\$self->{'_connection'}}': could not load DBD::SQLite: ${error}";
  0            
27 0           };
28              
29 0           my $database = $self->{'_database'};
30 0           my $charset = $self->{'_charset'};
31              
32             # if autocommit isn't configured then enable it by default
33 0 0         my $autocommit = (defined($self->{'_autocommit'}) ? ($self->{'_autocommit'} =~ /^(1|true|yes)$/ix ? 1 : 0) : 1);
    0          
34              
35 0           my $dsn = "dbi:SQLite:dbname=${database}";
36              
37 0           my $params = {
38             'AutoCommit' => $autocommit,
39             'RaiseError' => 1,
40             'PrintError' => 0,
41             };
42 0 0 0       if ($charset && $charset =~ /^utf8$/xi) {
43 0           $params->{'sqlite_unicode'} = 1;
44             }
45              
46             # merge in any additional dsn_params
47 0           $params = $self->_merge($params, $self->{'_dsn_extra'});
48              
49 0           $self->{'_dsn'} = [ $dsn, undef, undef, $params ];
50 0           return $self;
51             }
52              
53             1;