source: server/trunk/web/lib/Sophie/Base.pm @ 114

Last change on this file since 114 was 42, checked in by nanardon, 13 years ago
  • add dump/load distrib config using Yaml
  • separate DB connection for session
File size: 992 bytes
Line 
1package Sophie::Base;
2
3use strict;
4use warnings;
5use DBI;
6use base qw/DBIx::Class::Schema/;
7use FindBin qw($Bin);
8use Config::General;
9
10__PACKAGE__->load_namespaces();
11
12sub 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
24sub 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
38sub db {
39   my ($self) = @_;
40
41   $self->connect->storage->dbh;
42}
43
44
45
461;
Note: See TracBrowser for help on using the repository browser.