line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::Mysql; |
2
|
1
|
|
|
1
|
|
741
|
use Mojo::Base 'Mojolicious::Plugin'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
5
|
|
3
|
1
|
|
|
1
|
|
147
|
use FindBin; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
45
|
|
4
|
1
|
|
|
1
|
|
4
|
use lib "$FindBin::Bin/../lib/"; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
5
|
|
5
|
1
|
|
|
1
|
|
107
|
use MojoX::Mysql; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
7
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub register { |
8
|
1
|
|
|
1
|
1
|
47
|
my ($self, $app, $config) = @_; |
9
|
1
|
|
|
|
|
1
|
my %config; |
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
|
|
2
|
my $mysql = MojoX::Mysql->new(%{$config}); |
|
1
|
|
|
|
|
8
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# MojoX |
14
|
|
|
|
|
|
|
$app->helper(mysql=>sub { |
15
|
2
|
|
|
2
|
|
36109
|
my ($self) = @_; |
16
|
2
|
|
|
|
|
54
|
return $mysql; |
17
|
1
|
|
|
|
|
15
|
}); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# Hook Commit |
20
|
|
|
|
|
|
|
$app->hook(after_dispatch => sub { |
21
|
1
|
|
|
1
|
|
60027
|
my $self = shift; |
22
|
1
|
|
|
|
|
4
|
my $exception = $self->stash('exception'); |
23
|
1
|
50
|
|
|
|
12
|
if(defined $exception){ |
24
|
1
|
|
|
|
|
11
|
$self->mysql->db->rollback(); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
else{ |
27
|
0
|
|
|
|
|
0
|
$self->mysql->db->commit(); |
28
|
0
|
|
|
|
|
0
|
$self->mysql->db->disconnect(); |
29
|
|
|
|
|
|
|
} |
30
|
1
|
|
|
|
|
94
|
}); |
31
|
1
|
|
|
|
|
31
|
return $mysql; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
1; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=encoding utf8 |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head1 SYNOPSIS |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
my %config = ( |
41
|
|
|
|
|
|
|
user=>'root', |
42
|
|
|
|
|
|
|
password=>undef, |
43
|
|
|
|
|
|
|
server=>[ |
44
|
|
|
|
|
|
|
{dsn=>'database=test;host=localhost;port=3306;mysql_connect_timeout=5;', type=>'master'}, |
45
|
|
|
|
|
|
|
{dsn=>'database=test;host=localhost;port=3306;mysql_connect_timeout=5;', type=>'slave'}, |
46
|
|
|
|
|
|
|
{dsn=>'database=test;host=localhost;port=3306;mysql_connect_timeout=5;', id=>1, type=>'master'}, |
47
|
|
|
|
|
|
|
{dsn=>'database=test;host=localhost;port=3306;mysql_connect_timeout=5;', id=>1, type=>'slave'}, |
48
|
|
|
|
|
|
|
{dsn=>'database=test;host=localhost;port=3306;mysql_connect_timeout=5;', id=>2, type=>'master'}, |
49
|
|
|
|
|
|
|
{dsn=>'database=test;host=localhost;port=3306;mysql_connect_timeout=5;', id=>2, type=>'slave'}, |
50
|
|
|
|
|
|
|
] |
51
|
|
|
|
|
|
|
); |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# Mojolicious |
54
|
|
|
|
|
|
|
$self->plugin('Mysql'=>\%config); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# Mojolicious::Lite |
57
|
|
|
|
|
|
|
plugin 'Mysql' => \%config; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head1 HELPERS |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head2 mysql |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
$app->mysql; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
Return L object. |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=cut |
68
|
|
|
|
|
|
|
|