line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Nephia::Plugin::Teng; |
2
|
3
|
|
|
3
|
|
194755
|
use 5.008005; |
|
3
|
|
|
|
|
13
|
|
|
3
|
|
|
|
|
224
|
|
3
|
3
|
|
|
3
|
|
19
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
109
|
|
4
|
3
|
|
|
3
|
|
19
|
use warnings; |
|
3
|
|
|
|
|
15
|
|
|
3
|
|
|
|
|
98
|
|
5
|
3
|
|
|
3
|
|
3394
|
use Teng::Schema::Loader; |
|
3
|
|
|
|
|
159390
|
|
|
3
|
|
|
|
|
95
|
|
6
|
3
|
|
|
3
|
|
26688
|
use DBI; |
|
3
|
|
|
|
|
58251
|
|
|
3
|
|
|
|
|
241
|
|
7
|
3
|
|
|
3
|
|
1139
|
use parent 'Nephia::Plugin'; |
|
3
|
|
|
|
|
364
|
|
|
3
|
|
|
|
|
29
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = "0.04"; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new { |
12
|
2
|
|
|
2
|
0
|
401
|
my ($class, %opts) = @_; |
13
|
2
|
|
|
|
|
21
|
my $self = $class->SUPER::new(%opts); |
14
|
2
|
|
|
|
|
177
|
$self->{RUN_SQL} = []; |
15
|
2
|
|
|
|
|
8
|
return $self; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
4
|
|
|
4
|
1
|
36016
|
sub exports { qw/database_do teng/ } |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub database_do { |
21
|
6
|
|
|
6
|
1
|
43
|
my $self = shift; |
22
|
6
|
|
|
|
|
10
|
my $context = shift; |
23
|
6
|
|
|
|
|
27
|
$self->_load_context_config($context); |
24
|
|
|
|
|
|
|
return sub ($) { |
25
|
2
|
|
|
2
|
|
609
|
my $sql = shift; |
26
|
2
|
|
|
|
|
4
|
push @{$self->{RUN_SQL}}, $sql; |
|
2
|
|
|
|
|
6
|
|
27
|
6
|
|
|
|
|
68
|
}; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub _on_connect_do { |
31
|
1
|
|
|
1
|
|
2
|
my $self = shift; |
32
|
1
|
|
|
|
|
3
|
my $dbh = $self->_create_dbh(); |
33
|
1
|
|
|
|
|
14987
|
my @RUN_SQL = @{$self->{RUN_SQL}}; |
|
1
|
|
|
|
|
6
|
|
34
|
1
|
|
|
|
|
3
|
for my $sql (@RUN_SQL) { |
35
|
2
|
|
|
|
|
201058
|
$dbh->do($sql); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub teng { |
40
|
6
|
|
|
6
|
1
|
41
|
my $self = shift; |
41
|
6
|
|
|
|
|
9
|
my $context = shift; |
42
|
6
|
|
|
|
|
15
|
$self->_load_context_config($context); |
43
|
|
|
|
|
|
|
return sub (@) { |
44
|
2
|
|
66
|
2
|
|
2383
|
$self->{teng} ||= $self->_create_teng(); |
45
|
6
|
|
|
|
|
137
|
}; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub _create_teng { |
49
|
1
|
|
|
1
|
|
2
|
my $self = shift; |
50
|
1
|
|
|
|
|
3
|
my $config = $self->{opts}; |
51
|
1
|
|
33
|
|
|
11
|
my $pkg = $config->{teng_namespace} // $self->app->{caller}.'::DB'; |
52
|
|
|
|
|
|
|
|
53
|
1
|
|
|
|
|
12
|
$self->_on_connect_do(); |
54
|
|
|
|
|
|
|
|
55
|
1
|
|
|
|
|
52166
|
my $teng = |
56
|
|
|
|
|
|
|
Teng::Schema::Loader->load( |
57
|
|
|
|
|
|
|
dbh => $self->_create_dbh(), |
58
|
|
|
|
|
|
|
namespace => $pkg |
59
|
|
|
|
|
|
|
); |
60
|
|
|
|
|
|
|
|
61
|
1
|
|
|
|
|
53477
|
for my $plugin (@{$config->{teng_plugins}}) { |
|
1
|
|
|
|
|
7
|
|
62
|
0
|
|
|
|
|
0
|
$pkg->load_plugin($plugin); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
1
|
|
|
|
|
50
|
return $teng; |
66
|
|
|
|
|
|
|
}; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub _create_dbh { |
69
|
2
|
|
|
2
|
|
7
|
my $self = shift; |
70
|
2
|
|
|
|
|
6
|
my @connect_info; |
71
|
|
|
|
|
|
|
|
72
|
2
|
50
|
33
|
|
|
17
|
@connect_info = @{$self->{opts}->{connect_info}} |
|
0
|
|
|
|
|
0
|
|
73
|
|
|
|
|
|
|
if exists $self->{opts}->{connect_info} |
74
|
|
|
|
|
|
|
&& ref $self->{opts}->{connect_info} eq "ARRAY"; |
75
|
2
|
50
|
33
|
|
|
36
|
@connect_info = @{$self->{config}->{DBI}->{connect_info}} |
|
2
|
|
33
|
|
|
15
|
|
76
|
|
|
|
|
|
|
if !@connect_info |
77
|
|
|
|
|
|
|
&& exists $self->{config}->{DBI}->{connect_info} |
78
|
|
|
|
|
|
|
&& ref $self->{config}->{DBI}->{connect_info} eq "ARRAY"; |
79
|
|
|
|
|
|
|
|
80
|
2
|
|
|
|
|
17
|
return DBI->connect(@connect_info); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub _load_context_config { |
84
|
12
|
|
|
12
|
|
16
|
my $self = shift; |
85
|
12
|
|
|
|
|
16
|
my $context = shift; |
86
|
12
|
|
|
|
|
34
|
$self->{config} = $context->get('config'); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
1; |
90
|
|
|
|
|
|
|
__END__ |