line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::Environ::Mojo::Pg; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.2'; |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
538
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
34
|
|
6
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
7
|
1
|
|
|
1
|
|
21
|
use v5.10; |
|
1
|
|
|
|
|
2
|
|
8
|
1
|
|
|
1
|
|
3
|
use utf8; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
5
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
428
|
use App::Environ; |
|
1
|
|
|
|
|
499
|
|
|
1
|
|
|
|
|
26
|
|
11
|
1
|
|
|
1
|
|
405
|
use App::Environ::Config; |
|
1
|
|
|
|
|
10543
|
|
|
1
|
|
|
|
|
31
|
|
12
|
1
|
|
|
1
|
|
471
|
use Params::Validate qw(validate_pos); |
|
1
|
|
|
|
|
6381
|
|
|
1
|
|
|
|
|
53
|
|
13
|
1
|
|
|
1
|
|
478
|
use URI; |
|
1
|
|
|
|
|
2995
|
|
|
1
|
|
|
|
|
24
|
|
14
|
1
|
|
|
1
|
|
425
|
use Mojo::Pg; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
my %PG; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
App::Environ::Config->register(qw(pg.yml)); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub pg { |
21
|
|
|
|
|
|
|
my $class = shift; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
my ($connector) = validate_pos( @_, 1 ); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
unless ( defined $PG{$connector} ) { |
26
|
|
|
|
|
|
|
my $pg_string = $class->pg_string($connector); |
27
|
|
|
|
|
|
|
$PG{$connector} = Mojo::Pg->new($pg_string); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
my $conf = App::Environ::Config->instance->{pg}{connectors}{$connector}; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
if ( $conf->{max_connections} ) { |
32
|
|
|
|
|
|
|
$PG{$connector}->max_connections( $conf->{max_connections} ); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
if ( $conf->{migrations} && defined $conf->{migrations}{file} ) { |
36
|
|
|
|
|
|
|
if ( defined $conf->{migrations}{name} ) { |
37
|
|
|
|
|
|
|
$PG{$connector}->migrations->name( $conf->{migrations}{name} ); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
$PG{$connector}->migrations->from_file( $conf->{migrations}{file} ); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
return $PG{$connector}; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub pg_string { |
48
|
|
|
|
|
|
|
my $class = shift; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
my ($connector) = validate_pos( @_, 1 ); |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
my $conf = App::Environ::Config->instance->{pg}{connectors}{$connector}; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
my $url = URI->new(); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
## Non standart schema workaround |
57
|
|
|
|
|
|
|
## For URI objects that do not belong to one of these, you can only use the common and generic methods. |
58
|
|
|
|
|
|
|
$url->scheme('https'); |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
$url->userinfo("$conf->{user}:$conf->{password}"); |
61
|
|
|
|
|
|
|
$url->host( $conf->{host} ); |
62
|
|
|
|
|
|
|
$url->port( $conf->{port} ); |
63
|
|
|
|
|
|
|
$url->path( $conf->{dbname} ); |
64
|
|
|
|
|
|
|
$url->query_form( %{ $conf->{options} } ); |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
$url->scheme('postgresql'); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
return $url->as_string; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
1; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
__END__ |