File Coverage

blib/lib/Prancer/Plugin/Database/Driver/Mock.pm
Criterion Covered Total %
statement 32 35 91.4
branch 2 6 33.3
condition n/a
subroutine 9 10 90.0
pod 0 1 0.0
total 43 52 82.6


line stmt bran cond sub pod time code
1             package Prancer::Plugin::Database::Driver::Mock;
2              
3 2     2   1532 use strict;
  2         3  
  2         93  
4 2     2   9 use warnings FATAL => 'all';
  2         3  
  2         69  
5              
6 2     2   8 use version;
  2         2  
  2         11  
7             our $VERSION = '1.02';
8              
9 2     2   543 use Prancer::Plugin::Database::Driver;
  2         4  
  2         54  
10 2     2   10 use parent qw(Prancer::Plugin::Database::Driver);
  2         2  
  2         12  
11              
12 2     2   131 use Try::Tiny;
  2         2  
  2         104  
13 2     2   8 use Carp;
  2         3  
  2         596  
14              
15             # even though this *should* work automatically, it was not
16             our @CARP_NOT = qw(Prancer Try::Tiny);
17              
18             sub new {
19 7     7 0 9 my $class = shift;
20 7         32 my $self = bless($class->SUPER::new(@_), $class);
21              
22             try {
23 7     7   782 require DBD::Mock;
24             } catch {
25 0 0   0   0 my $error = (defined($_) ? $_ : "unknown");
26 0         0 croak "could not initialize database connection '${\$self->{'_connection'}}': could not load DBD::Mock: ${error}";
  0         0  
27 7         51 };
28              
29 7         10212 my $database = $self->{'_database'};
30              
31             # if autocommit isn't configured then enable it by default
32 7 50       62 my $autocommit = (defined($self->{'_autocommit'}) ? ($self->{'_autocommit'} =~ /^(1|true|yes)$/ix ? 1 : 0) : 1);
    50          
33              
34 7         8 my $dsn = "dbi:Mock:";
35              
36 7         22 my $params = {
37             'AutoCommit' => $autocommit,
38             'RaiseError' => 1,
39             'PrintError' => 0,
40             };
41              
42             # merge in any additional dsn_params
43 7         37 $params = $self->_merge($params, $self->{'_dsn_extra'});
44              
45 7         25 $self->{'_dsn'} = [ $dsn, undef, undef, $params ];
46 7         23 return $self;
47             }
48              
49             1;