Database/Driver/MySQL.pm

filter: Statementstmt 51.0% 24 / 47 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 70.0% 7 / 10 Podpod 0.0% 0 / 1 totaltotal 41.3% 31 / 75 CC 8 SCAR 31.9
CC
8
Cov
39%
new
56.0
__ANON__
6.0
__ANON__
2.0
CRAP 24.3
↑ Summary Database/Driver/Pg.pm »
1 package Prancer::Plugin::Database::Driver::MySQL;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use version;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 our $VERSION = '1.04';
8  
9 1 ▶use Prancer::Plugin::Database::Driver;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use parent qw(Prancer::Plugin::Database::Driver);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 # even though this *should* work automatically, it was not
16 1 our @CARP_NOT = qw(Prancer Try::Tiny);
17  
18 0 ▶sub new {
Subroutine new: not called CC=7 SCAR=40.3
Pod undocumented
19 0 my $class = shift;
20 0 my $self = bless($class->SUPER::new(@_), $class);
21  
22 0 ▶ try {
Subroutine __ANON__: not called CC=1 SCAR=6.9
23 0 require DBD::mysql;
24 0 ▶ } catch {
Subroutine __ANON__: not called CC=2 SCAR=17.9
25 0 ▶ my $error = (defined($_) ? $_ : "unknown");
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 0 0 0
26 0 croak "could not initialize database connection '${\$self->{'_connection'}}': could not load DBD::mysql: ${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  
36 # if autocommit isn't configured then enable it by default
37 0 ▶ my $autocommit = (defined($self->{'_autocommit'}) ? ($self->{'_autocommit'} =~ /^(1|true|yes)$/ix ? 1 : 0) : 1);
Branch: 2 branches
BranchTrueFalseTotal
defined $self->{'_autocommit'} ? : 0 0 0
$self->{'_autocommit'} =~ /^(1|true|yes)$/xi ? : 0 0 0
38  
39 0 my $dsn = "dbi:mysql:dbname=${database}";
40 0 ▶ $dsn .= ";host=${hostname}" if defined($hostname);
Branch: 1 branch
BranchTrueFalseTotal
if defined $hostname 0 0 0
41 0 ▶ $dsn .= ";port=${port}" if defined($port);
Branch: 1 branch
BranchTrueFalseTotal
if defined $port 0 0 0
42  
43 0 my $params = {
44 'AutoCommit' => $autocommit,
45 'RaiseError' => 1,
46 'PrintError' => 0,
47 };
48 0 ▶ if ($charset && $charset =~ /^utf8$/xi) {
Branch: 1 branch
BranchTrueFalseTotal
if ($charset and $charset =~ /^utf8$/xi) 0 0 0
Condition0%0/3
$charset and $charset =~ /^utf8$/xi
!ll&&!rl&&r
000
MC/DC0%0/2
$charset and $charset =~ /^utf8$/xi
$charset $charset =~ /^utf8$/xi
Truth table0%0/3
A and B
A= $charsetB= $charset =~ /^utf8$/xi
ABresult
0X0
100
111
49 0 $params->{'mysql_enable_utf8'} = 1;
50 }
51  
52 # merge in any additional dsn_params
53 0 $params = $self->_merge($params, $self->{'_dsn_extra'});
54  
55 0 $self->{'_dsn'} = [ $dsn, $username, $password, $params ];
56 0 return $self;
57 }
58  
59 1 1;
↑ Summary Database/Driver/Pg.pm »