line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::Prove::Plugin::MultipleConfig; |
2
|
1
|
|
|
1
|
|
774
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
3
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
24
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
437
|
use POSIX::AtFork; |
|
1
|
|
|
|
|
499
|
|
|
1
|
|
|
|
|
48
|
|
6
|
1
|
|
|
1
|
|
1533
|
use DBI; |
|
1
|
|
|
|
|
17590
|
|
|
1
|
|
|
|
|
58
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
417
|
use ConfigCache; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
329
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub load { |
13
|
0
|
|
|
0
|
0
|
|
my ($class, $prove) = @_; |
14
|
|
|
|
|
|
|
|
15
|
0
|
|
|
|
|
|
my @args = @{$prove->{args}}; |
|
0
|
|
|
|
|
|
|
16
|
0
|
|
|
|
|
|
foreach (@args) { $_ =~ s/"//g; } |
|
0
|
|
|
|
|
|
|
17
|
0
|
|
|
|
|
|
my $module = shift @args; |
18
|
0
|
|
|
|
|
|
my @configs = @args; |
19
|
0
|
|
0
|
|
|
|
my $jobs = $prove->{ app_prove }->jobs || 1; |
20
|
0
|
0
|
|
|
|
|
if (scalar @configs < $jobs){ |
21
|
0
|
|
|
|
|
|
die "the number of dsn(" . scalar @configs . ") must be grater than jobs: $jobs."; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
0
|
0
|
|
|
|
|
if ($module){ |
25
|
0
|
0
|
|
|
|
|
eval "require $module" ## no critic |
26
|
|
|
|
|
|
|
or die "$@"; |
27
|
|
|
|
|
|
|
|
28
|
0
|
|
|
|
|
|
for my $config (@configs){ |
29
|
0
|
|
|
|
|
|
my $valid = do $config; |
30
|
0
|
0
|
|
|
|
|
if (!defined $valid){ |
31
|
0
|
|
|
|
|
|
die "argument: $config is invalid"; |
32
|
|
|
|
|
|
|
} |
33
|
0
|
0
|
|
|
|
|
$module->can("prepare") ? $module->prepare($config) : die "$module don't have prepare method"; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
ConfigCache->set_configs(\@configs); |
38
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
$prove->{ app_prove }->formatter('TAP::Formatter::MultipleConfig'); |
40
|
0
|
|
|
|
|
|
$prove->{ app_prove }->harness('TAP::Harness::MultipleConfig'); |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
POSIX::AtFork->add_to_child( \&child_hook ); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub child_hook { |
47
|
0
|
|
|
0
|
0
|
|
my ($call) = @_; |
48
|
0
|
0
|
|
|
|
|
($call eq 'fork') or return; |
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
my $config = ConfigCache->pop_configs(); |
51
|
0
|
|
|
|
|
|
ConfigCache->set_config_by_pid($$, $config); |
52
|
0
|
|
|
|
|
|
$ENV{ PERL_MULTIPLE_CONFIG } = $config; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
1; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
__END__ |