File Coverage

blib/lib/Pgtools/Connection.pm
Criterion Covered Total %
statement 19 21 90.4
branch 11 14 78.5
condition n/a
subroutine 4 5 80.0
pod 0 2 0.0
total 34 42 80.9


line stmt bran cond sub pod time code
1             package Pgtools::Connection;
2 3     3   23703 use strict;
  3         4  
  3         64  
3 3     3   8 use warnings;
  3         5  
  3         60  
4              
5 3     3   370 use parent qw(Class::Accessor);
  3         273  
  3         13  
6             __PACKAGE__->mk_accessors(qw(dbh host port user password database));
7              
8             sub set_args {
9 6     6 0 8419 my $self = shift;
10 6         7 my ($option) = @_;
11 6         17 my @tmp = split(/,/, $option, -1);
12 6 100       13 if($#tmp != 4) {
13 3         17 die "Invalid arguments.\nPlease check pg_config_diff -help\n";
14             }
15 3 100       12 $self->set("host", $tmp[0]) if $tmp[0] ne '';
16 3 100       21 $self->set("port", $tmp[1]) if $tmp[1] ne '';
17 3 50       14 $self->set("user", $tmp[2]) if $tmp[2] ne '';
18 3 100       14 $self->set("password", $tmp[3]) if $tmp[3] ne '';
19 3 100       11 $self->set("database", $tmp[4]) if $tmp[4] ne '';
20             }
21              
22             sub create_connection {
23 0     0 0   my $self = shift;
24              
25 0 0         $self->set("dbh", DBI->connect(
26             "dbi:Pg:dbname=".$self->database.";host=".$self->host.";port=".$self->port,
27             $self->user,
28             $self->password
29             )) or die "$!\n Error: failed to connect to DB.\n";
30             }
31              
32              
33              
34             1;