DBIx::Simple with automated connect to starcraft database.
Configured through @Games::StarCraft::DB::Conf, set in untracked
Games::StarCraft::DB::Local class (loaded automatically).
Replaces manual DBIx::Simple setup with config from dbinfo.inc.pl.
--- /dev/null
+/Games/StarCraft/DB/Local.pm
--- /dev/null
+package Games::StarCraft::DB;
+
+use strict;
+use warnings;
+use DBIx::Simple;
+use Carp;
+use base 'DBIx::Simple';
+
+our $VERSION = '1.00';
+our @Conf; # database connect options
+
+sub connect {
+ my $self = shift;
+ eval { require Games::StarCraft::DB::Local }; # local @Conf overrides
+ my @options = @Conf;
+ if (@_ >= 1 and ref (my $manual = shift) eq "HASH") {
+ while (my ($key, $value) = each %$manual) {
+ $options[3]->{$key} = $value;
+ }
+ }
+ return $self->SUPER::connect(@options);
+}
+
+1;
+
my $place = $placetxt{$placeid} or die "Unknown place id: $placeid\n";
print "Resolved place '$placeid' to $place\n" if $DBG;
my $place = $placetxt{$placeid} or die "Unknown place id: $placeid\n";
print "Resolved place '$placeid' to $place\n" if $DBG;
-use DBIx::Simple;
-my @dbinfo = do "dbinfo.inc.pl";
-my $Db = DBIx::Simple->connect(@dbinfo, {pg_enable_utf8 => 1})
+use Games::StarCraft::DB;
+my $Db = Games::StarCraft::DB->connect
or die "No database: $DBI::errstr\n";
$TEST and exit;
or die "No database: $DBI::errstr\n";
$TEST and exit;