Last change
on this file since 170 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
|
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 | |
---|
[42] | 12 | sub default_config { |
---|
[24] | 13 | my $config; |
---|
[25] | 14 | foreach my $file ('sophie.conf', "$Bin/../sophie.conf", |
---|
| 15 | '/etc/sophie/sophie.conf') { |
---|
[24] | 16 | -f $file or next; |
---|
| 17 | my $cg = Config::General->new($file); |
---|
| 18 | $config = { $cg->getall() }; |
---|
| 19 | } |
---|
| 20 | $config or die "No config found"; |
---|
[42] | 21 | return $config; |
---|
| 22 | } |
---|
[2] | 23 | |
---|
[42] | 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 | ) |
---|
[2] | 36 | } |
---|
| 37 | |
---|
[42] | 38 | sub db { |
---|
| 39 | my ($self) = @_; |
---|
[2] | 40 | |
---|
[42] | 41 | $self->connect->storage->dbh; |
---|
| 42 | } |
---|
[2] | 43 | |
---|
[42] | 44 | |
---|
| 45 | |
---|
[2] | 46 | 1; |
---|
Note: See
TracBrowser
for help on using the repository browser.