File Coverage

blib/lib/Prancer/Plugin/Database/Driver/Mock.pm
Criterion Covered Total %
statement 31 34 91.1
branch 2 6 33.3
condition n/a
subroutine 9 10 90.0
pod 0 1 0.0
total 42 51 82.3


line stmt bran cond sub pod time code
1             package Prancer::Plugin::Database::Driver::Mock;
2              
3 1     1   657 use strict;
  1         1  
  1         57  
4 1     1   4 use warnings FATAL => 'all';
  1         1  
  1         42  
5              
6 1     1   3 use version;
  1         1  
  1         7  
7             our $VERSION = '1.00';
8              
9 1     1   468 use Prancer::Plugin::Database::Driver;
  1         1  
  1         27  
10 1     1   4 use parent qw(Prancer::Plugin::Database::Driver);
  1         1  
  1         8  
11              
12 1     1   66 use Try::Tiny;
  1         1  
  1         39  
13 1     1   4 use Carp;
  1         1  
  1         248  
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         30 my $self = bless($class->SUPER::new(@_), $class);
21              
22             try {
23 7     7   921 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         45 };
28              
29 7         10361 my $database = $self->{'_database'};
30              
31             # if autocommit isn't configured then enable it by default
32 7 50       66 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         28 my $params = {
37             'AutoCommit' => $autocommit,
38             'RaiseError' => 1,
39             'PrintError' => 0,
40             };
41              
42 7         23 $self->{'_dsn'} = [ $dsn, undef, undef, $params ];
43 7         25 return $self;
44             }
45              
46             1;