| 1 | package Test::Chado::DBManager::Postgression; | ||
| 2 | { | ||
| 3 | $Test::Chado::DBManager::Postgression::VERSION = 'v4.1.1'; | ||
| 4 | } | ||
| 5 | |||
| 6 | 1 | ▶ | use namespace::autoclean; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | 1 | ▶ | use Moo; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | 1 | ▶ | use DBI; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | 1 | ▶ | use HTTP::Tiny; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 10 | 0 | ▶ | use JSON; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 11 | use feature qw/say/; | ||
| 12 | extends qw/Test::Chado::DBManager::Pg/; | ||
| 13 | |||
| 14 | sub _build_dbh { | ||
| 15 | my ($self) = @_; | ||
| 16 | my $ua = HTTP::Tiny->new( | ||
| 17 | default_headers => { 'Accept' => 'application/json' } ); | ||
| 18 | my $response = $ua->get('http://api.postgression.com'); | ||
| 19 | |||
| 20 | if (!$response->{success}) { | ||
| 21 | say "request to postgression failed !!!!"; | ||
| 22 | die "status: $response->{status}\treason: $response->{reason}\n"; | ||
| 23 | } | ||
| 24 | |||
| 25 | my $resp_hash = decode_json $response->{content}; | ||
| 26 | my $dsn | ||
| 27 | = "dbi:Pg:dbname=$resp_hash->{dbname};host=$resp_hash->{host};port=$resp_hash->{port}"; | ||
| 28 | $self->dsn($dsn); | ||
| 29 | $self->user( $resp_hash->{username} ); | ||
| 30 | $self->password( $resp_hash->{password} ); | ||
| 31 | |||
| 32 | my $attr = $self->dbi_attributes; | ||
| 33 | $attr->{AutoCommit} = 1; | ||
| 34 | my $dbh = DBI->connect( $self->dsn, $self->user, $self->password, $attr ); | ||
| 35 | $dbh->do(qq{SET client_min_messages=WARNING}); | ||
| 36 | return $dbh; | ||
| 37 | } | ||
| 38 | |||
| 39 | 1; | ||
| 40 | |||
| 41 | __END__ | ||