comparison cpt_psm_prep/lib/CPT/Chado/GMOD_Conf.pm @ 0:e4de0a0e90c8 draft

Uploaded
author cpt
date Tue, 05 Jul 2022 05:38:34 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:e4de0a0e90c8
1 package CPT::Chado::GMOD_Conf;
2 use Moose;
3
4 has 'database_identifier' => ( is => 'rw', isa => 'Str' );
5 has 'gmod_root' => ( is => 'rw', isa => 'Str', default => '/usr/share/gmod/' );
6 has 'database' => ( is => 'rw', isa => 'Str' );
7 has 'username' => ( is => 'rw', isa => 'Str' );
8 has 'password' => ( is => 'rw', isa => 'Str' );
9 has 'host' => ( is => 'rw', isa => 'Str', default => 'localhost' );
10 has 'port' => ( is => 'rw', isa => 'Int', default => 5432 );
11
12 sub load_config {
13 my ( $self, $identifier ) = @_;
14 open( my $db_info, '<',
15 $self->gmod_root() . "conf/${identifier}.conf" );
16 while (<$db_info>) {
17 chomp $_;
18 if ( $_ =~ /DBUSER=/ ) {
19 $self->username( substr( $_, 7 ) );
20 }
21 elsif ( $_ =~ /DBPASS=/ ) {
22 $self->password( substr( $_, 7 ) );
23 }
24 elsif ( $_ =~ /DBNAME=/ ) {
25 $self->database( substr( $_, 7 ) );
26 }
27 }
28 close($db_info);
29 }
30
31 sub get_connector {
32 my ( $self, $identifier ) = @_;
33 $self->load_config($identifier);
34 use DBI;
35 my $dbh = DBI->connect(
36 sprintf(
37 "dbi:Pg:dbname=%s;host=%s;port=%s;",
38 $self->database(), $self->host(), $self->port()
39 ),
40 $self->username(),
41 $self->password()
42 );
43 return $dbh;
44 }
45
46 no Moose;
47 1;
48
49 __END__
50
51 =pod
52
53 =encoding UTF-8
54
55 =head1 NAME
56
57 CPT::Chado::GMOD_Conf
58
59 =head1 VERSION
60
61 version 1.99.4
62
63 =head1 AUTHOR
64
65 Eric Rasche <rasche.eric@yandex.ru>
66
67 =head1 COPYRIGHT AND LICENSE
68
69 This software is Copyright (c) 2014 by Eric Rasche.
70
71 This is free software, licensed under:
72
73 The GNU General Public License, Version 3, June 2007
74
75 =cut