screp: postpone loading modules for optional features
authorShiar <shiar@shiar.org>
Sun, 28 Sep 2008 03:06:09 +0000 (05:06 +0200)
committerShiar <shiar@shiar.org>
Mon, 17 Nov 2008 16:38:50 +0000 (17:38 +0100)
Load modules at runtime, so they do not need to be installed if they
aren't used.

screp

diff --git a/screp b/screp
index dc24f05259d103026a968787d00f6ff0c21dcedc..29b7e0b1acb437dfb6e6a1d703a8ae3eb9400bd4 100755 (executable)
--- a/screp
+++ b/screp
@@ -174,7 +174,7 @@ if ($ACTGIF) {
        binmode $imgfile;
        select $imgfile;
 
-       use GD;
+       require GD;
        my $ani = GD::Image->new($head->{width}, $head->{height});
        my $bg = $ani->colorAllocate(0, 0, 0);
        my @plot = (
@@ -216,9 +216,12 @@ if ($ACTGIF) {
        select STDOUT;
 }
 
-use Games::StarCraft::DB;
+if ($DBGAME or $DBNAME) {
+
+require Games::StarCraft::DB;
 my $Db = Games::StarCraft::DB->connect({RaiseError => 1})
        or die "No database: $DBI::errstr\n";
+
 sub findaccount ($) {
        my ($name) = @_;
        my $query = $Db->query(q{
@@ -306,6 +309,8 @@ if ($DBNAME) {
        $Db->commit;
 }
 
+}
+
 if ($APMSVG) {
        my @seq;  # player => time (s) => actions
        $seq[$_->[1]][$_->[0] * .042]++ for @$map;
@@ -324,7 +329,7 @@ if ($APMSVG) {
        }
 
        BEGIN { unshift @INC, '.' }
-       use SVG::TT::Graph::TimeSeries;
+       require SVG::TT::Graph::TimeSeries;
        my $graph = SVG::TT::Graph::TimeSeries->new({
                height => 1200,
                width => 1600,