line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Prancer::Plugin::Database::Driver::MySQL; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
716
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
49
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings FATAL => 'all'; |
|
1
|
|
|
|
|
0
|
|
|
1
|
|
|
|
|
33
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
3
|
use version; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
5
|
|
7
|
|
|
|
|
|
|
our $VERSION = '1.04'; |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
67
|
use Prancer::Plugin::Database::Driver; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
16
|
|
10
|
1
|
|
|
1
|
|
4
|
use parent qw(Prancer::Plugin::Database::Driver); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
4
|
|
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
50
|
use Try::Tiny; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
44
|
|
13
|
1
|
|
|
1
|
|
10
|
use Carp; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
427
|
|
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::mysql; |
24
|
|
|
|
|
|
|
} catch { |
25
|
0
|
0
|
|
0
|
|
|
my $error = (defined($_) ? $_ : "unknown"); |
26
|
0
|
|
|
|
|
|
croak "could not initialize database connection '${\$self->{'_connection'}}': could not load DBD::mysql: ${error}"; |
|
0
|
|
|
|
|
|
|
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
|
0
|
|
|
|
|
my $autocommit = (defined($self->{'_autocommit'}) ? ($self->{'_autocommit'} =~ /^(1|true|yes)$/ix ? 1 : 0) : 1); |
|
|
0
|
|
|
|
|
|
38
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
my $dsn = "dbi:mysql:dbname=${database}"; |
40
|
0
|
0
|
|
|
|
|
$dsn .= ";host=${hostname}" if defined($hostname); |
41
|
0
|
0
|
|
|
|
|
$dsn .= ";port=${port}" if defined($port); |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
my $params = { |
44
|
|
|
|
|
|
|
'AutoCommit' => $autocommit, |
45
|
|
|
|
|
|
|
'RaiseError' => 1, |
46
|
|
|
|
|
|
|
'PrintError' => 0, |
47
|
|
|
|
|
|
|
}; |
48
|
0
|
0
|
0
|
|
|
|
if ($charset && $charset =~ /^utf8$/xi) { |
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; |