Rev | Line | |
---|
[2] | 1 | package Sophie::Base; |
---|
| 2 | |
---|
| 3 | use strict; |
---|
| 4 | use warnings; |
---|
| 5 | use DBI; |
---|
| 6 | use base qw/DBIx::Class::Schema/; |
---|
[18] | 7 | use FindBin qw($Bin); |
---|
[26] | 8 | use Config::General; |
---|
[2] | 9 | |
---|
| 10 | __PACKAGE__->load_namespaces(); |
---|
| 11 | |
---|
| 12 | sub connection { |
---|
| 13 | my ($class) = @_; |
---|
| 14 | $class->SUPER::connection( |
---|
| 15 | sub { __PACKAGE__->db }, |
---|
| 16 | ) |
---|
| 17 | } |
---|
| 18 | |
---|
| 19 | sub db { |
---|
| 20 | my ($self) = @_; |
---|
[24] | 21 | my $config; |
---|
[25] | 22 | foreach my $file ('sophie.conf', "$Bin/../sophie.conf", |
---|
| 23 | '/etc/sophie/sophie.conf') { |
---|
[24] | 24 | -f $file or next; |
---|
| 25 | my $cg = Config::General->new($file); |
---|
| 26 | $config = { $cg->getall() }; |
---|
| 27 | } |
---|
| 28 | $config or die "No config found"; |
---|
[2] | 29 | |
---|
| 30 | DBI->connect_cached( |
---|
[18] | 31 | 'dbi:Pg:' . $config->{dbconnect}, |
---|
| 32 | $config->{dbuser}, |
---|
| 33 | $config->{dbpassword}, |
---|
[2] | 34 | { |
---|
| 35 | AutoCommit => 0, |
---|
[5] | 36 | PrintError => 1, |
---|
[2] | 37 | } |
---|
| 38 | ); |
---|
| 39 | } |
---|
| 40 | |
---|
| 41 | |
---|
| 42 | |
---|
| 43 | 1; |
---|
Note: See
TracBrowser
for help on using the repository browser.