#!/usr/bin/perl -w
######################################################################
### finance-quote-check - check for the presence of  Finance::Quote
### From finance-quote-helper.
### Copyright 2001 Rob Browning <rlb@cs.utexas.edu>
### 
### This program is free software; you can redistribute it and/or    
### modify it under the terms of the GNU General Public License as   
### published by the Free Software Foundation; either version 2 of   
### the License, or (at your option) any later version.              
###                                                                  
### This program is distributed in the hope that it will be useful,  
### but WITHOUT ANY WARRANTY; without even the implied warranty of   
### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    
### GNU General Public License for more details.                     
###                                                                  
### You should have received a copy of the GNU General Public License
### along with this program# if not, contact:
###
### Free Software Foundation           Voice:  +1-617-542-5942
### 59 Temple Place - Suite 330        Fax:    +1-617-542-2652
### Boston, MA  02111-1307,  USA       gnu@gnu.org
######################################################################

use lib '/usr/libdata/perl5/i386-openbsd/5.8.6';

use strict;
use English;
use FileHandle;

# Input: <none>
#
# Output (on standard output, one output form per input line):
#
# A list of quote sources supported by Finance::Quote, or the single
# term missing-lib if finance quote could not be executed.
#
# Exit status
#
# 0 - success
# non-zero - failure

sub check_modules {
  my @modules = qw(Date::Manip HTML::Parser Finance::Quote LWP);
  my @missing;

  foreach my $mod (@modules) {
    if (eval "require $mod") {
      $mod->import();
    }
    else {
      push (@missing, $mod);
    }
  }

  return unless @missing;

  print STDERR "\n";
  print STDERR "You need to install the following Perl modules:\n";
  foreach my $mod (@missing) {
    print STDERR "  ".$mod."\n";
  }

  print STDERR "\n";
  print STDERR "Run 'update-finance-quote' as root to install them.\n";

  print "missing-lib\n";

  exit 1;
}

#---------------------------------------------------------------------------
# Runtime.

# Check for and load non-standard modules
check_modules ();

# Create a stockquote object.
my $quoter = Finance::Quote->new();
my $prgnam = "scmio-finance-quote";

my @qsources;
my @sources = $quoter->sources();
foreach my $source (@sources) {
  push(@qsources, "\"$source\"");
}
printf "(%s)\n", join(" ", qq/@qsources/);

## Local Variables:
## mode: perl
## End:
