use MIME::Base64 ();
use Storable;
use Data::Dumper;
+use Hash::Merge;
+use YAML;
+use Cwd qw( abs_path );
$Data::Dumper::Indent = 1;
$Data::Dumper::Sortkeys = 1;
my $db = 'books';
my $title = "Sitzungsdaten:";
-my $dsn = 'DBI:mysql:database=' . $db . ';host=localhost';
-my $user = 'books';
-my $password = 'uhu';
my $attrs = {
'AutoCommit' => 1,
'PrintError' => 0,
'RaiseError' => 0,
};
-my $schema = FrBr::Books::Db->connect( $dsn, $user, $password, $attrs );
+my $dbconf = {
+ 'host' => 'localhost',
+ 'port' => 3306,
+ 'db' => 'books',
+ 'user' => 'books',
+ 'pwd' => 'uhu',
+};
+config();
+
+my $dsn = sprintf( 'DBI:mysql:database=%s;host=%s%s', $dbconf->{'db'}, $dbconf->{'host'}, $dbconf->{'port'} == 3306 ? '' : ( ';port=' . $dbconf->{'port'} ) );
+
+my $schema = FrBr::Books::Db->connect( $dsn, $dbconf->{'user'}, $dbconf->{'pwd'}, $attrs );
my @all_items = $schema->resultset('Session')->search( undef, {
'columns' => [ qw/
exit 0;
+#--------------------------------------------------------------------------------
+
+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 $cnf_normal = read_yml($conf_file_normal);
+ my $cnf_local = read_yml($conf_file_local);
+
+ unless ( $cnf_normal ) {
+ common_notice( "Konfiguraionsdatei '" . $conf_file_normal . "' konnte nicht gelesen werden." );
+ exit 66;
+ }
+
+ my $conf;
+ if ( $cnf_local ) {
+ Hash::Merge::set_behavior( 'RIGHT_PRECEDENT' );
+ $conf = Hash::Merge::merge( $cnf_normal, $cnf_local );
+ }
+ else {
+ $conf = $cnf_normal;
+ }
+
+ $dbconf->{'host'} = $conf->{'database'}{'host'} if $conf->{'database'}{'host'};
+ $dbconf->{'port'} = to_int( $conf->{'database'}{'port'} ) if $conf->{'database'}{'port'} and to_int( $conf->{'database'}{'port'} );
+ $dbconf->{'db'} = $conf->{'database'}{'schema'} if $conf->{'database'}{'schema'};
+ $dbconf->{'user'} = $conf->{'database'}{'user'} if $conf->{'database'}{'user'};
+ $dbconf->{'pwd'} = $conf->{'database'}{'passwd'} if $conf->{'database'}{'passwd'};
+
+}
+
+#--------------------------------------------------------------------------------
+
+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 :