line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package ActiveRecord::Simple::Connect; |
2
|
|
|
|
|
|
|
|
3
|
12
|
|
|
12
|
|
66
|
use strict; |
|
12
|
|
|
|
|
18
|
|
|
12
|
|
|
|
|
282
|
|
4
|
12
|
|
|
12
|
|
49
|
use warnings; |
|
12
|
|
|
|
|
17
|
|
|
12
|
|
|
|
|
226
|
|
5
|
12
|
|
|
12
|
|
149
|
use 5.010; |
|
12
|
|
|
|
|
33
|
|
6
|
|
|
|
|
|
|
|
7
|
12
|
|
|
12
|
|
11141
|
use DBI; |
|
12
|
|
|
|
|
127699
|
|
|
12
|
|
|
|
|
3986
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
my $self; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
8
|
|
|
8
|
0
|
25
|
my ($class, $dsn, $username, $password, $params) = @_; |
14
|
|
|
|
|
|
|
|
15
|
8
|
50
|
|
|
|
54
|
if (!$self) { |
16
|
8
|
|
|
|
|
22
|
$self = { dbh => undef }; |
17
|
8
|
100
|
|
|
|
25
|
if ($dsn) { |
18
|
6
|
|
|
|
|
10
|
$self->{dsn} = $dsn; |
19
|
6
|
50
|
|
|
|
20
|
$self->{username} = $username if $username; |
20
|
6
|
50
|
|
|
|
18
|
$self->{password} = $password if $password; |
21
|
6
|
50
|
|
|
|
21
|
$self->{connection_parameters} = $params if $params; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
8
|
|
|
|
|
16
|
bless $self, $class; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
8
|
|
|
|
|
24
|
return $self; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub db_connect { |
31
|
6
|
|
|
6
|
0
|
14
|
my ($self) = @_; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
$self->{dbh} = DBI->connect( |
34
|
|
|
|
|
|
|
$self->{dsn}, |
35
|
|
|
|
|
|
|
$self->{username}, |
36
|
|
|
|
|
|
|
$self->{password}, |
37
|
6
|
50
|
|
|
|
53
|
) or die DBI->errstr; |
38
|
|
|
|
|
|
|
|
39
|
6
|
|
|
|
|
15732
|
return $self; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub username { |
43
|
0
|
|
|
0
|
0
|
0
|
my ($self, $username) = @_; |
44
|
|
|
|
|
|
|
|
45
|
0
|
0
|
|
|
|
0
|
$self->{username} = $username if $username; |
46
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
0
|
return $self->{username}; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub password { |
51
|
0
|
|
|
0
|
0
|
0
|
my ($self, $password) = @_; |
52
|
|
|
|
|
|
|
|
53
|
0
|
0
|
|
|
|
0
|
$self->{password} = $password if $password; |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
0
|
return $self->{password}; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub dsn { |
59
|
0
|
|
|
0
|
0
|
0
|
my ($self, $dsn) = @_; |
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
0
|
$self->{dsn} = $dsn; |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
0
|
return $self->{dsn}; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub connection_parameters { |
67
|
0
|
|
|
0
|
0
|
0
|
my ($self, $connection_parameters) = @_; |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
0
|
$self->{connection_parameters} = $connection_parameters; |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
0
|
return $self->{connection_parameters}; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub dbh { |
75
|
362
|
|
|
362
|
0
|
497
|
my ($self, $dbh) = @_; |
76
|
|
|
|
|
|
|
|
77
|
362
|
100
|
|
|
|
530
|
$self->{dbh} = $dbh if $dbh; |
78
|
362
|
50
|
33
|
|
|
1394
|
$self->db_connect unless $self->{dbh} && $self->{dbh}->ping; |
79
|
|
|
|
|
|
|
|
80
|
362
|
|
|
|
|
4976
|
return $self->{dbh}; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
1; |