X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?a=blobdiff_plain;f=yarrg%2FCommodsWeb.pm;h=37bbfe7dcbcc2d878eb5a2d7016458b616358e35;hb=f7c3c04f684b0e9cac4518beeece11853ef75109;hp=00c6f24b8cc5ce0ce9713592de4897428ffcdcd6;hpb=2abd3537af0c697684bfb97895f230372101329d;p=ypp-sc-tools.db-live.git diff --git a/yarrg/CommodsWeb.pm b/yarrg/CommodsWeb.pm index 00c6f24..37bbfe7 100644 --- a/yarrg/CommodsWeb.pm +++ b/yarrg/CommodsWeb.pm @@ -50,7 +50,7 @@ BEGIN { @ISA = qw(Exporter); @EXPORT = qw(&dbw_connect &dbw_filename &ocean_list &sourcebasedir &to_json_shim &to_json_protecttags - &set_ctype_utf8 + &set_ctype_utf8 &webdatadir &printable &expected_error &dbw_lookup_string &prettyprint_age &meta_prettyprint_age); %EXPORT_TAGS = ( ); @@ -73,20 +73,25 @@ sub sourcebasedir () { return dotperllibdir().'/..'; } -sub datadir () { - my $edir= $ENV{'YARRG_DATA_DIR'}; +sub some_datadir ($) { + my ($what) = @_; + my $edir= $ENV{"YARRG_${what}_DIR"}; return $edir if defined $edir; my $dir= dotperllibdir(); - if (stat "$dir/DATA") { - return "$dir/DATA"; + my $dirwhat= "$dir/$what"; + if (stat $dirwhat) { + return $dirwhat; } elsif ($!==&ENOENT) { return "$dir"; } else { - die "stat $dir/DATA $!"; + die "stat $dirwhat $!"; } return '.'; } +sub webdatadir () { return some_datadir('WEBDATA'); } +sub datadir () { return some_datadir('DATA'); } + my @ocean_list; sub ocean_list () { @@ -195,6 +200,15 @@ sub expected_error ($) { die $r; } +sub printable ($) { # printable($m) where $m is the Mason request object + my ($m) = @_; + my $a= scalar $m->caller_args(-1); + foreach my $t (qw(pdf ps html)) { + return $t if $a->{"printable_$t"}; + } + return 0; +} + package CommodsWeb::ExpectedError; sub emsg ($) {