X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?a=blobdiff_plain;f=yarrg%2FCommodsWeb.pm;h=5e1520e22f45a3e0d3853f53e6523f1b370e6e5c;hb=555fcf1a304c5f1aef9384c3c4d07d5255a0f05d;hp=96dde357c9bb40c31d3f7b399848ce9002d1167e;hpb=5b9cc22ec3ee084ba46a83c0ae99f4831317ff9d;p=ypp-sc-tools.main.git diff --git a/yarrg/CommodsWeb.pm b/yarrg/CommodsWeb.pm index 96dde35..5e1520e 100644 --- a/yarrg/CommodsWeb.pm +++ b/yarrg/CommodsWeb.pm @@ -36,26 +36,51 @@ use Commods; use CommodsDatabase; our $self_url; +our $base_url; BEGIN { use Exporter (); our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS); $VERSION = 1.00; @ISA = qw(Exporter); - @EXPORT = qw($dbh &db_setocean &db_connect &db_doall - $self_url); + @EXPORT = qw(&dbw_connect &ocean_list); %EXPORT_TAGS = ( ); @EXPORT_OK = qw(); } +our $datadir='.'; + for my $dir (@INC) { if ($dir =~ m/\.perl-lib$/) { - db_setdatadir("$dir/DATA"); + $datadir= "$dir/DATA"; last; } } -$self_url= 'http://'.$ENV{'SERVER_NAME'}.$ENV{'SCRIPT_NAME'}.$ENV{'PATH_INFO'}; +my @ocean_list; + +sub ocean_list () { + if (!@ocean_list) { + my $fn= "$datadir/master-info.txt"; + my $f= new IO::File $fn or die $!; + my @r; + while (<$f>) { + next unless m/^ocean\s+(\S.*\S)\s*$/; + push @r, $1; + } + $f->error and die $!; + close $fn; + @ocean_list= @r; + } + return @ocean_list; +} + +sub dbw_connect ($) { + my ($ocean) = @_; + die "unknown ocean $ocean ?" + unless grep { $_ eq $ocean } ocean_list(); + return dbr_connect($datadir, $ocean); +} 1;