Games::StarCraft::DB class for schtarr database
authorShiar <shiar@shiar.org>
Thu, 17 Jan 2008 06:16:07 +0000 (06:16 +0000)
committerShiar <shiar@shiar.org>
Thu, 17 Jan 2008 06:16:07 +0000 (06:16 +0000)
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.

.gitignore [new file with mode: 0644]
Games/StarCraft/DB.pm [new file with mode: 0644]
pvpgnreport

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..79842f4
--- /dev/null
@@ -0,0 +1 @@
+/Games/StarCraft/DB/Local.pm
diff --git a/Games/StarCraft/DB.pm b/Games/StarCraft/DB.pm
new file mode 100644 (file)
index 0000000..11b645e
--- /dev/null
@@ -0,0 +1,25 @@
+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;
+
index fc0a038032e956dd4aed7574fe7348bebf47aa42..1f1abea19554cfa8e9f631be12d5b94b707fcfd7 100755 (executable)
@@ -41,9 +41,8 @@ my ($placeid) = $name =~ /.*([a-z]{2})/;
 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;