Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- exodist@dev1 $ cat lib/OpenExodus/Model/Schema.pm [~/projects/oe.net]
- package OpenExodus::Model::Schema;
- use strict;
- use warnings;
- use Fey::DBIManager::Source;
- use Fey::Loader;
- use YAML qw/LoadFile/;
- use Fey::ORM::Schema;
- use Moose;
- use MooseX::ClassAttribute;
- class_has config => (
- isa => 'Hash',
- is => 'ro',
- default => sub {
- my $file = $ENV{'RTK_DB_CONF'} || 'dbconf.yaml';
- return LoadFile( $file ) if -e $file;
- return {};
- },
- );
- class_has source => (
- isa => 'Fey::DBIManager::Source',
- is => 'ro',
- default => sub {
- Fey::DBIManager::Source->new(
- dsn => 'dbi:Pg:dbname=' . ($ENV{RTK_DB} || __PACKAGE__->config->{database}),
- username => $ENV{RTK_DB_USER} || __PACKAGE__->config->{username},
- password => $ENV{RTK_DB_PASS} || __PACKAGE__->config->{password},
- );
- },
- );
- sub dbh {
- my $class = shift;
- return $class->source->dbh();
- }
- has_schema( Fey::Loader->new( dbh => __PACKAGE__->dbh() )->make_schema() );
- __PACKAGE__->DBIManager()->add_source( __PACKAGE__->source );
- 1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement