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

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