From: Shiar Date: Thu, 17 Jan 2008 06:16:07 +0000 (+0000) Subject: Games::StarCraft::DB class for schtarr database X-Git-Url: http://git.shiar.nl/perl/schtarr.git/commitdiff_plain/b08934a82682226827ca788bd143c37d8e476b53 Games::StarCraft::DB class for schtarr database 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. --- diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..79842f4 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/Games/StarCraft/DB/Local.pm diff --git a/Games/StarCraft/DB.pm b/Games/StarCraft/DB.pm new file mode 100644 index 0000000..11b645e --- /dev/null +++ b/Games/StarCraft/DB.pm @@ -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; + diff --git a/pvpgnreport b/pvpgnreport index fc0a038..1f1abea 100755 --- a/pvpgnreport +++ b/pvpgnreport @@ -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;