chiark / gitweb /
prettyprint_age moved to commodsweb
authorIan Jackson <ian@liberator.relativity.greenend.org.uk>
Mon, 24 Aug 2009 02:18:24 +0000 (03:18 +0100)
committerIan Jackson <ian@liberator.relativity.greenend.org.uk>
Mon, 24 Aug 2009 02:18:24 +0000 (03:18 +0100)
yarrg/CommodsWeb.pm
yarrg/web/query_age

index d423a299c48136c20d7fe9ab3c408cffba402ec7..f0c183ce0872adb68b31a1d80b5f3849659a9b3e 100644 (file)
@@ -53,7 +53,8 @@ BEGIN {
     @ISA         = qw(Exporter);
     @EXPORT      = qw(&dbw_connect &ocean_list $sourcebasedir
                      &to_json_shim &to_json_protecttags
-                     &set_ctype_utf8);
+                     &set_ctype_utf8
+                     &prettyprint_age &meta_prettyprint_age);
     %EXPORT_TAGS = ( );
 
     @EXPORT_OK   = qw();
@@ -121,4 +122,25 @@ sub to_json_protecttags ($) {
     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 "$@";
+}
+
+
 1;
index 28d6a5f667074203c49451d522ad55b7d9fb1254..a90ca3469811b249d5d9c3cde0364d63a136662b 100644 (file)
@@ -40,24 +40,6 @@ $dbh
 </%args>
 
 <%once>
-my $meta_prettyprint_age= sub {
-    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
-};
-
-my $prettyprint_age;
-eval '
-  $prettyprint_age= sub {
-               my ($age) = @_;
-               '.$meta_prettyprint_age->('$age','floor','.').'
-  };
-' or die "$@";
 
 </%once>
 
@@ -97,7 +79,7 @@ $sth->execute();
 <tr id=<% $rowid %>
    > <td><% $row->{'archipelago'} |h
   %> <td><% $row->{'islandname'} |h
-  %> <td id="<% $cellid %>"><% $prettyprint_age->($age) %> </tr>
+  %> <td id="<% $cellid %>"><% prettyprint_age($age) %> </tr>
 % }
 </table>
 
@@ -129,7 +111,7 @@ Time since this page loaded:
       var cellid= 'c'+rowid;
       var el= document.getElementById(cellid);
       var age= oldage + (now - da_pageload) / 1000;
-      var newhtml= <% $meta_prettyprint_age->('age','Math.floor','+') %>;
+      var newhtml= <% meta_prettyprint_age('age','Math.floor','+') %>;
 % if ($ARGS{debug}) {
       if (cellid == 'cid_loaded')
        debug('element rowid='+rowid+' cellid='+cellid