| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Pask::Config; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
8
|
use Carp; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
45
|
|
|
4
|
1
|
|
|
1
|
|
107
|
use Config::INI::Reader; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use Pask::Container; |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub parse_mysql_config { |
|
9
|
|
|
|
|
|
|
my $config = shift; |
|
10
|
|
|
|
|
|
|
my $prefix = $config->{"prefix"}; |
|
11
|
|
|
|
|
|
|
foreach (keys %{$config->{"schema"}}) { |
|
12
|
|
|
|
|
|
|
Pask::Container::set_database_config "$prefix$_", { |
|
13
|
|
|
|
|
|
|
"dsn" => "DBI:mysql:" . $config->{"schema"}{$_} . ";host=" . $config->{"ip"}, |
|
14
|
|
|
|
|
|
|
"username" => $config->{"username"}, |
|
15
|
|
|
|
|
|
|
"password" => $config->{"password"}, |
|
16
|
|
|
|
|
|
|
"options" => { mysql_enable_utf8 => 1 } |
|
17
|
|
|
|
|
|
|
}; |
|
18
|
|
|
|
|
|
|
} |
|
19
|
|
|
|
|
|
|
} |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub parse_database_config { |
|
22
|
|
|
|
|
|
|
my $config = shift; |
|
23
|
|
|
|
|
|
|
my $database = $config->{"global"}{"database"}; |
|
24
|
|
|
|
|
|
|
foreach (keys %{$database}) { |
|
25
|
|
|
|
|
|
|
my $database_config = undef; |
|
26
|
|
|
|
|
|
|
if ($database->{$_}) { |
|
27
|
|
|
|
|
|
|
$database_config = $config->{$database->{$_}} if $database->{$_}; |
|
28
|
|
|
|
|
|
|
Carp::confess "can not find database ", $database->{$_}, " config" unless $database_config; |
|
29
|
|
|
|
|
|
|
if ($config->{"global"}{"default_database"} eq $_) { |
|
30
|
|
|
|
|
|
|
$database_config->{"prefix"} = ""; |
|
31
|
|
|
|
|
|
|
} else { |
|
32
|
|
|
|
|
|
|
$database_config->{"prefix"} = "$_."; |
|
33
|
|
|
|
|
|
|
} |
|
34
|
|
|
|
|
|
|
parse_mysql_config $database_config if $database_config->{"type"} =~ /mysql/i; |
|
35
|
|
|
|
|
|
|
} |
|
36
|
|
|
|
|
|
|
} |
|
37
|
|
|
|
|
|
|
} |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub parse_env_file { |
|
40
|
|
|
|
|
|
|
use Data::Dumper; |
|
41
|
|
|
|
|
|
|
my ($orginal, $target, $i, $prev_i, $prev_key) = (Config::INI::Reader->read_file(shift)); |
|
42
|
|
|
|
|
|
|
foreach my $key (keys %$orginal) { |
|
43
|
|
|
|
|
|
|
$target->{$key} = {}; |
|
44
|
|
|
|
|
|
|
foreach my $name (keys %{$orginal->{$key}}) { |
|
45
|
|
|
|
|
|
|
if ($name =~ /^\w+?(\.\w+){1,}$/) { |
|
46
|
|
|
|
|
|
|
$i = $target->{$key}; |
|
47
|
|
|
|
|
|
|
foreach (split /\./, $name) { |
|
48
|
|
|
|
|
|
|
$i->{$_} = {} unless exists $i->{$_}; |
|
49
|
|
|
|
|
|
|
$prev_i = $i; |
|
50
|
|
|
|
|
|
|
$prev_key = $_; |
|
51
|
|
|
|
|
|
|
$i = $i->{$_}; |
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
$prev_i->{$prev_key} = $orginal->{$key}{$name}; |
|
54
|
|
|
|
|
|
|
} else { |
|
55
|
|
|
|
|
|
|
$target->{$key}{$name} = $orginal->{$key}{$name}; |
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
} |
|
58
|
|
|
|
|
|
|
} |
|
59
|
|
|
|
|
|
|
parse_database_config $target; |
|
60
|
|
|
|
|
|
|
$orginal; |
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
1; |