line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Database::Util; |
2
|
|
|
|
|
|
|
$Test::Database::Util::VERSION = '1.113'; |
3
|
5
|
|
|
5
|
|
28867
|
use strict; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
182
|
|
4
|
5
|
|
|
5
|
|
28
|
use warnings; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
192
|
|
5
|
5
|
|
|
5
|
|
25
|
use Carp; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
412
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# export everything |
8
|
|
|
|
|
|
|
sub import { |
9
|
5
|
|
|
5
|
|
17
|
my $caller = caller(); |
10
|
5
|
|
|
5
|
|
23
|
no strict 'refs'; |
|
5
|
|
|
|
|
7
|
|
|
5
|
|
|
|
|
2264
|
|
11
|
5
|
|
|
|
|
19
|
*{"${caller}::$_"} = \&$_ for qw( _read_file ); |
|
5
|
|
|
|
|
133
|
|
12
|
|
|
|
|
|
|
} |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# return a list of hashrefs representing each configuration section |
15
|
|
|
|
|
|
|
sub _read_file { |
16
|
6
|
|
|
6
|
|
5864
|
my ($file) = @_; |
17
|
6
|
|
|
|
|
10
|
my @config; |
18
|
|
|
|
|
|
|
|
19
|
6
|
100
|
|
|
|
532
|
open my $fh, '<', $file or croak "Can't open $file for reading: $!"; |
20
|
5
|
|
|
|
|
25
|
my $re_header = qr/^(?:(?:driver_)?dsn|key)$/; |
21
|
5
|
|
|
|
|
11
|
my %args; |
22
|
|
|
|
|
|
|
my $records; |
23
|
5
|
|
|
|
|
70872
|
while (<$fh>) { |
24
|
45
|
100
|
|
|
|
202
|
next if /^\s*(?:#|$)/; # skip blank lines and comments |
25
|
20
|
|
|
|
|
29
|
chomp; |
26
|
|
|
|
|
|
|
|
27
|
20
|
100
|
|
|
|
98
|
/\s*(\w+)\s*=\s*(.*)\s*/ && do { |
28
|
19
|
|
|
|
|
56
|
my ( $key, $value ) = ( $1, $2 ); |
29
|
19
|
100
|
|
|
|
112
|
if ( $key =~ $re_header ) { |
|
|
100
|
|
|
|
|
|
30
|
8
|
100
|
|
|
|
38
|
push @config, {%args} if keys %args; |
31
|
8
|
|
|
|
|
13
|
$records++; |
32
|
8
|
|
|
|
|
18
|
%args = (); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
elsif ( !$records ) { |
35
|
1
|
|
|
|
|
206
|
croak "Record doesn't start with dsn or driver_dsn or key " |
36
|
|
|
|
|
|
|
. "at $file, line $.:\n <$_>"; |
37
|
|
|
|
|
|
|
} |
38
|
18
|
|
|
|
|
48
|
$args{$key} = $value; |
39
|
18
|
|
|
|
|
61
|
next; |
40
|
|
|
|
|
|
|
}; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# unknown line |
43
|
1
|
|
|
|
|
216
|
croak "Can't parse line at $file, line $.:\n <$_>"; |
44
|
|
|
|
|
|
|
} |
45
|
3
|
100
|
|
|
|
22
|
push @config, {%args} if keys %args; |
46
|
3
|
|
|
|
|
42
|
close $fh; |
47
|
|
|
|
|
|
|
|
48
|
3
|
|
|
|
|
44
|
return @config; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
'USING'; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
__END__ |