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