use Storable;
use Data::Dumper;
use Catalyst::Utils;
-use YAML;
+use Config::Any;
use Cwd qw( abs_path );
$Data::Dumper::Indent = 1;
$Data::Dumper::Sortkeys = 1;
-my $db = 'books';
my $title = "Sitzungsdaten:";
-my $attrs = {
- 'AutoCommit' => 1,
- 'PrintError' => 0,
- 'RaiseError' => 0,
+my $config = {
+ 'schema_class' => 'CoNet::SwAdmin::Schema',
+ 'connect_info' => {
+ 'AutoCommit' => 1,
+ 'PrintError' => 0,
+ 'RaiseError' => 0,
+ 'quote_char' => '`',
+ 'name_sep' => '.',
+ 'on_connect_do' => [
+ "SET NAMES 'utf8'",
+ ],
+ },
};
-my $dbuser = 'books';
-my $dbpwd = '';
-
-my $dsn = 'DBI:mysql:database=books;host=localhost';
-
config();
-my $schema = FrBr::Books::Db->connect( $dsn, $dbuser, $dbpwd, $attrs );
+my $schema = $config->{'schema_class'}->connect( $config->{'connect_info'} );
my @all_items = $schema->resultset('Session')->search( undef, {
'columns' => [ qw/
sub config {
- my $conf_file_normal = abs_path( $FindBin::Bin . "/../frbr_books.yml" );
- my $conf_file_local = abs_path( $FindBin::Bin . "/../frbr_books_local.yml" );
+ my $stems = [ ];
- my $cnf_normal = read_yml($conf_file_normal);
- my $cnf_local = read_yml($conf_file_local);
+ $stems = [ abs_path( $FindBin::Bin . "/../frbr_books" ) ];
+ my $cfg = Config::Any->load_stems( { stems => $stems, flatten_to_hash => 0, use_ext => 1 } );
+ #print Dumper( $cfg );
- unless ( $cnf_normal ) {
- common_notice( "Konfiguraionsdatei '" . $conf_file_normal . "' konnte nicht gelesen werden." );
- exit 66;
+ for my $file ( keys %$cfg ) {
+ if ( $cfg->{$file}{'Model::Schema'} ) {
+ $config = Catalyst::Utils::merge_hashes( $config, $cfg->{$file}{'Model::Schema'} );
+ }
}
- my $conf;
- if ( $cnf_local ) {
- $conf = Catalyst::Utils::merge_hashes( $cnf_normal, $cnf_local );
- }
- else {
- $conf = $cnf_normal;
- }
+ $stems = [ abs_path( $FindBin::Bin . "/../frbr_books_local" ) ];
+ $cfg = Config::Any->load_stems( { stems => $stems, flatten_to_hash => 0, use_ext => 1 } );
+ #print Dumper( $cfg );
- if ( $conf->{'Model::Schema'}{'connect_info'} ) {
- my $c = $conf->{'Model::Schema'}{'connect_info'};
- $dsn = $c->[0];
- $dbuser = $c->[1];
- $dbpwd = $c->[2];
- $attrs = $c->[3];
+ for my $file ( keys %$cfg ) {
+ if ( $cfg->{$file}{'Model::Schema'} ) {
+ $config = Catalyst::Utils::merge_hashes( $config, $cfg->{$file}{'Model::Schema'} );
+ }
}
}
#--------------------------------------------------------------------------------
-sub read_yml {
-
- my $file = shift;
-
- return undef unless -f $file;
-
- my $cnf = undef;
- eval {
- $cnf = YAML::LoadFile($file);
- };
- if ( $@ ) {
- common_notice( "Fehler beim Lesen der YAML-Datei '" . $file . "': ", $@ );
- }
-
- return $cnf;
-
-}
-
__END__
# vim: noai : ts=4 fenc=utf-8 filetype=perl expandtab :