Last change
on this file since 114 was
42,
checked in by nanardon, 14 years ago
|
- add dump/load distrib config using Yaml
- separate DB connection for session
|
File size:
992 bytes
|
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 | use Config::General; |
---|
9 | |
---|
10 | __PACKAGE__->load_namespaces(); |
---|
11 | |
---|
12 | sub default_config { |
---|
13 | my $config; |
---|
14 | foreach my $file ('sophie.conf', "$Bin/../sophie.conf", |
---|
15 | '/etc/sophie/sophie.conf') { |
---|
16 | -f $file or next; |
---|
17 | my $cg = Config::General->new($file); |
---|
18 | $config = { $cg->getall() }; |
---|
19 | } |
---|
20 | $config or die "No config found"; |
---|
21 | return $config; |
---|
22 | } |
---|
23 | |
---|
24 | sub connection { |
---|
25 | my ($class, $connect_info) = @_; |
---|
26 | if (! $connect_info->{dsn}) { |
---|
27 | my $config = default_config(); |
---|
28 | $connect_info->{dsn} = 'dbi:Pg:' . $config->{dbconnect}; |
---|
29 | $connect_info->{user} = $config->{dbuser}; |
---|
30 | $connect_info->{password} = $config->{dbpassword}; |
---|
31 | } |
---|
32 | exists($connect_info->{AutoCommit}) or $connect_info->{AutoCommit} = 0; |
---|
33 | $class->SUPER::connection( |
---|
34 | $connect_info, |
---|
35 | ) |
---|
36 | } |
---|
37 | |
---|
38 | sub db { |
---|
39 | my ($self) = @_; |
---|
40 | |
---|
41 | $self->connect->storage->dbh; |
---|
42 | } |
---|
43 | |
---|
44 | |
---|
45 | |
---|
46 | 1; |
---|
Note: See
TracBrowser
for help on using the repository browser.