line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DBD::Mock::dr; |
2
|
|
|
|
|
|
|
|
3
|
39
|
|
|
39
|
|
288
|
use strict; |
|
39
|
|
|
|
|
73
|
|
|
39
|
|
|
|
|
1216
|
|
4
|
39
|
|
|
39
|
|
192
|
use warnings; |
|
39
|
|
|
|
|
79
|
|
|
39
|
|
|
|
|
1408
|
|
5
|
|
|
|
|
|
|
|
6
|
39
|
|
|
39
|
|
231
|
use List::Util qw(reduce); |
|
39
|
|
|
|
|
80
|
|
|
39
|
|
|
|
|
37631
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $imp_data_size = 0; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
my @connect_callbacks; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub connect { |
14
|
79
|
|
|
79
|
0
|
9636
|
my ( $drh, $dbname, $user, $auth, $attributes ) = @_; |
15
|
79
|
100
|
|
|
|
301
|
if ( $drh->{'mock_connect_fail'} == 1 ) { |
16
|
1
|
|
|
|
|
13
|
$drh->set_err( 1, "Could not connect to mock database" ); |
17
|
1
|
|
|
|
|
15
|
return; |
18
|
|
|
|
|
|
|
} |
19
|
78
|
|
100
|
|
|
296
|
$attributes ||= {}; |
20
|
|
|
|
|
|
|
|
21
|
78
|
|
|
|
|
261
|
my %driverParameters = _parse_driver_dsn( $dbname ); |
22
|
|
|
|
|
|
|
|
23
|
78
|
100
|
100
|
|
|
298
|
if ( $dbname && $DBD::Mock::AttributeAliasing ) { |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# this is the DB we are mocking |
26
|
|
|
|
|
|
|
$attributes->{mock_attribute_aliases} = |
27
|
7
|
|
|
|
|
21
|
DBD::Mock::_get_mock_attribute_aliases($driverParameters{database}); |
28
|
6
|
|
|
|
|
11
|
$attributes->{mock_database_name} = $driverParameters{database}; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# holds statement parsing coderefs/objects |
32
|
77
|
|
|
|
|
224
|
$attributes->{mock_parser} = []; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# holds all statements applied to handle until manually cleared |
35
|
77
|
|
|
|
|
212
|
$attributes->{mock_statement_history} = []; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# ability to fake a failed DB connection |
38
|
77
|
|
|
|
|
203
|
$attributes->{mock_can_connect} = 1; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# ability to make other things fail :) |
41
|
77
|
|
|
|
|
184
|
$attributes->{mock_can_prepare} = 1; |
42
|
77
|
|
|
|
|
191
|
$attributes->{mock_can_execute} = 1; |
43
|
77
|
|
|
|
|
162
|
$attributes->{mock_can_fetch} = 1; |
44
|
|
|
|
|
|
|
|
45
|
77
|
|
50
|
|
|
349
|
my $dbh = DBI::_new_dbh( $drh, { Name => $dbname } ) |
46
|
|
|
|
|
|
|
|| return; |
47
|
|
|
|
|
|
|
|
48
|
77
|
|
|
|
|
3406
|
foreach my $callback (@connect_callbacks) { |
49
|
5
|
|
|
|
|
16
|
$callback->( $dbh, $dbname, $user, $auth, $attributes ); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
77
|
|
|
|
|
387
|
return $dbh; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub FETCH { |
56
|
4
|
|
|
4
|
|
23
|
my ( $drh, $attr ) = @_; |
57
|
4
|
100
|
|
|
|
18
|
if ( $attr =~ /^mock_/ ) { |
58
|
3
|
50
|
|
|
|
14
|
if ( $attr eq 'mock_connect_fail' ) { |
|
|
100
|
|
|
|
|
|
59
|
0
|
|
|
|
|
0
|
return $drh->{'mock_connect_fail'}; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
elsif ( $attr eq 'mock_data_sources' ) { |
62
|
2
|
50
|
|
|
|
9
|
unless ( defined $drh->{'mock_data_sources'} ) { |
63
|
2
|
|
|
|
|
6
|
$drh->{'mock_data_sources'} = ['DBI:Mock:']; |
64
|
|
|
|
|
|
|
} |
65
|
2
|
|
|
|
|
9
|
return $drh->{'mock_data_sources'}; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
else { |
68
|
1
|
|
|
|
|
11
|
return $drh->SUPER::FETCH($attr); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
else { |
72
|
1
|
|
|
|
|
7
|
return $drh->SUPER::FETCH($attr); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub STORE { |
77
|
7
|
|
|
7
|
|
460
|
my ( $drh, $attr, $value ) = @_; |
78
|
7
|
100
|
|
|
|
35
|
if ( $attr =~ /^mock_/ ) { |
79
|
6
|
100
|
|
|
|
30
|
if ( $attr eq 'mock_connect_fail' ) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
80
|
2
|
100
|
|
|
|
10
|
return $drh->{'mock_connect_fail'} = $value ? 1 : 0; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
elsif ( $attr eq 'mock_data_sources' ) { |
83
|
1
|
50
|
|
|
|
7
|
if ( ref($value) ne 'ARRAY' ) { |
84
|
0
|
|
|
|
|
0
|
$drh->set_err( 1, |
85
|
|
|
|
|
|
|
"You must pass an array ref of data sources" ); |
86
|
0
|
|
|
|
|
0
|
return; |
87
|
|
|
|
|
|
|
} |
88
|
1
|
|
|
|
|
6
|
return $drh->{'mock_data_sources'} = $value; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
elsif ( $attr eq 'mock_add_data_sources' ) { |
91
|
2
|
|
|
|
|
6
|
return push @{ $drh->{'mock_data_sources'} } => $value; |
|
2
|
|
|
|
|
13
|
|
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
else { |
95
|
1
|
|
|
|
|
10
|
return $drh->SUPER::STORE( $attr, $value ); |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub data_sources { |
100
|
5
|
|
|
5
|
0
|
3131
|
my $drh = shift; |
101
|
|
|
|
|
|
|
return |
102
|
9
|
100
|
|
|
|
75
|
map { (/^DBI\:Mock\:/i) ? $_ : "DBI:Mock:$_" } |
103
|
5
|
|
|
|
|
10
|
@{ $drh->FETCH('mock_data_sources') }; |
|
5
|
|
|
|
|
26
|
|
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
# Necessary to support DBI < 1.34 |
107
|
|
|
|
|
|
|
# from CPAN RT bug #7057 |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
37
|
0
|
|
sub disconnect_all { |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
# no-op |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
0
|
|
|
0
|
|
0
|
sub DESTROY { undef } |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub set_connect_callbacks { |
117
|
3
|
50
|
|
3
|
0
|
110
|
@connect_callbacks = map { die "connect callbacks needs to be a reference to a function " unless ref $_ eq "CODE"; $_ } @_; |
|
3
|
|
|
|
|
11
|
|
|
3
|
|
|
|
|
17
|
|
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub add_connect_callbacks { |
121
|
1
|
50
|
|
1
|
0
|
11
|
push @connect_callbacks, map { die "connect callbacks needs to be a reference to a function " unless ref $_ eq "CODE"; $_ } @_; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
5
|
|
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub _parse_driver_dsn { |
125
|
78
|
|
|
78
|
|
178
|
my ( $driverDsn ) = @_; |
126
|
|
|
|
|
|
|
|
127
|
78
|
100
|
|
|
|
238
|
$driverDsn = $driverDsn ? $driverDsn : ''; |
128
|
|
|
|
|
|
|
|
129
|
78
|
|
|
|
|
136
|
my %driverParameters; |
130
|
|
|
|
|
|
|
|
131
|
78
|
|
|
|
|
295
|
foreach my $parameter ( split /;/, $driverDsn ) { |
132
|
14
|
100
|
|
|
|
71
|
if ( my ( $key, $value ) = $parameter =~ m/^(.*?)=(.*)$/ ) { |
133
|
8
|
|
|
|
|
22
|
$driverParameters{ $key } = $value; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
78
|
100
|
|
|
|
290
|
$driverParameters{database} = $driverDsn unless %driverParameters; |
138
|
|
|
|
|
|
|
|
139
|
78
|
|
|
|
|
363
|
return %driverParameters; |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
1; |