common: render time in footer on dev
[sheet.git] / common.inc.plp
index 54356fb42adfd24cab478beba319ee4adc794291..db5177b1a2f7fbb2b681857cbc496a7a838e89d2 100644 (file)
@@ -1,6 +1,6 @@
 <:
+use 5.014;
 use utf8;
-use strict;
 use warnings;
 no  warnings 'qw';  # you know what you doing
 no  warnings 'uninitialized';  # save some useless checks for more legible code
@@ -14,6 +14,11 @@ $PLP::ERROR = sub {
        print '<p class="error"><strong>Fatal error</strong>: '.$html."</p>\n\n";
 };
 
+BEGIN {
+       require Time::HiRes;
+       our $Time = [Time::HiRes::gettimeofday];
+}
+
 our $style;
 our $showkeys = !exists $get{keys} ? undef :
        ($get{keys} ne '0' && ($get{keys} || 'always'));
@@ -41,7 +46,7 @@ sub stylesheet {
 
        return join "\n", map { sprintf(
                '<link rel="%s" type="text/css" media="all" href="%s" title="%s">',
-               $_ eq $style ? 'stylesheet' : 'alternate stylesheet', "/$_.css?1.7", $_
+               $_ eq $style ? 'stylesheet' : 'alternate stylesheet', "/$_.css?1.9", $_
        ) } @_;
 }
 
@@ -117,6 +122,7 @@ EOT
        print qq{</head>\n\n<body id="$file">\n};
 
        # dev indicator
+       my $Dev = $ENV{HTTP_HOST} =~ /\bdev\./;
        printf '<p style="%s">beta</p>', join('; ',
                'position: fixed',
                'right: 1em',
@@ -125,7 +131,7 @@ EOT
                'border-width: 1ex 0',
                'z-index: 1',
                'background: inherit',
-       ) if $ENV{HTTP_HOST} =~ /\bdev\./;
+       ) if $Dev;
 
        # prepare trailing output
        PLP_END {
@@ -133,15 +139,16 @@ EOT
 <p class="footer">
        <a href="/" rel="start">sheet.shiar.nl</a>/$file.<a href="/source/$file.plp"
         rel="source" title="Written in Perl">plp</a>
-       <a href="http://git.shiar.nl/sheet.git/history/HEAD:/$file.plp"
-        rel="vcs-git" title="Git repository">v$meta->{version}</a>
+       version <a href="http://git.shiar.nl/sheet.git/history/HEAD:/$file.plp"
+        rel="vcs-git" title="Git repository">$meta->{version}</a>
        created by <a href="http://shiar.nl/" rel="author">Shiar</a> •
        <a href="http://www.fsf.org/licensing/licenses/agpl-3.0.html" rel="license copyright"
         title="Licensed under the GNU Affero General Public License, version 3">AGPLv3</a>
-</p>
-
-</html>
 EOT
+               say sprintf '• %.3fs', Time::HiRes::tv_interval($Time) if $Dev;
+               say '</p>';
+               say '';
+               say '</html>';
        };
 }