+defined $sourcebasedir or
+ die "no source base dir in @INC";
+
+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);
+}
+
+sub to_json_shim ($) {
+ my ($obj) = @_;
+ # In JSON.pm 2.x, jsonToObj prints a warning to stderr which
+ # our callers don't like at all.
+ if ($JSON::VERSION >= 2.0) {
+ return to_json($obj);
+ } else {
+ return objToJson($obj);
+ }
+}
+
+sub to_json_protecttags ($) {
+ my ($v) = @_;
+ my $j= to_json_shim($v);
+ $j =~ s,/,\\/,g;
+ return $j;
+}
+
+sub meta_prettyprint_age ($$$) {
+ my ($age,$floor,$plus) = @_;
+ return <<END;
+ $age < 60 ? 'less than a minute' :
+ $age < 60*2 ? '1 minute' :
+ $age < 3600*2 ? $floor ($age/60) $plus' minutes' :
+ $age < 86400*2 ? $floor ($age/3600) $plus ' hours' :
+ $floor ($age/86400) $plus ' days';
+END
+};
+
+BEGIN { eval '
+ sub prettyprint_age ($) {
+ my ($age) = @_;
+ '.meta_prettyprint_age('$age','floor','.').'
+ };
+ 1;
+' or die "$@";
+}
+