X-Git-Url: http://git.shiar.nl/sheet.git/blobdiff_plain/917ba679115b9e3cd7b88f7e5081a1a2503a684e..dc1ab5f00eed170e75fe40687b381369a35760b8:/common.inc.plp diff --git a/common.inc.plp b/common.inc.plp index 7788049..f7ca700 100644 --- a/common.inc.plp +++ b/common.inc.plp @@ -1,5 +1,6 @@ <: use 5.014; +use strict; use utf8; use warnings; no warnings 'qw'; # you know what you doing @@ -10,11 +11,13 @@ use File::stat 'stat'; use HTTP::Date; use Encode qw( decode_utf8 ); +our $Dev; + sub Alert { my ($html, $debug) = @_; ref $html eq 'ARRAY' or $html = [$html]; my ($title, @lines) = @{$html}; - $body = "

$title

"; + my $body = "

$title

"; $body .= "\n

$_

" for @lines; $body .= "\n
$debug
" if $Dev and $debug; say "
$body
\n"; @@ -38,27 +41,16 @@ BEGIN { require Time::HiRes; our $Time = [Time::HiRes::gettimeofday()]; - $PLP::ERROR = sub { - my ($text, $html) = @_; - warn $text; - unless ($PLP::sentheaders and $PLP::sentheaders->[0] !~ m{/PLP\.pm$}) { - Html({nocache => 1}); - say '

Page unavailable

'; - } - Alert("Fatal error: $html."); - }; - push @INC, '.'; # user request our $Dev = $ENV{HTTP_HOST} =~ /\bdev\./; - our ($file) = $ENV{SCRIPT_FILENAME} =~ m{ ([^/]+) \.plp$ }x; } -our $Request = decode_utf8($ENV{PATH_INFO} =~ s{^/}{}r); +our $Request //= decode_utf8($ENV{PATH_INFO} =~ s{^/}{}r); our $style; -our $showkeys = !exists $get{keys} ? undef : +our $showkeys //= !exists $get{keys} ? undef : ($get{keys} ne '0' && ($get{keys} || 'always')); $header{content_type} = 'text/html; charset=utf-8'; @@ -86,7 +78,7 @@ sub stylesheet { return map { sprintf( '', - $_ eq $style ? 'stylesheet' : 'alternate stylesheet', "/$_.css?1.11", $_ + $_ eq $style ? 'stylesheet' : 'alternate stylesheet', "/$_.css?1.12", $_ ) } @avail; } @@ -146,6 +138,8 @@ sub Html { '', ) if $meta->{keys}; + my ($file) = $ENV{SCRIPT_FILENAME} =~ m{ ([^/]+) \.plp$ }x; + PLP_START { # leading output say ''; @@ -156,9 +150,9 @@ sub Html { for $header{content_type}; say sprintf '%s', $meta->{title}; say sprintf '', EscapeHTML($_) - for join(' ', @{ $meta->{description} }) || (); + for join(' ', @{ $meta->{description} // [] }) || (); say sprintf '', EscapeHTML($_) - for join(', ', @{ $meta->{keywords} }) || (); + for join(', ', @{ $meta->{keywords} // [] }) || (); say ''; say ''; say for map { @{$_} } $meta->{raw} || (); @@ -192,6 +186,7 @@ sub Html { title="Licensed under the GNU Affero General Public License, version 3" rel="license">AGPLv3 EOT + our $Time; say sprintf '• %.3fs', Time::HiRes::tv_interval($Time) if $Dev and $Time; say '

'; say ''; @@ -199,6 +194,18 @@ EOT }; } +BEGIN { + $PLP::ERROR = sub { + my ($text, $html) = @_; + warn $text; + unless ($PLP::sentheaders) { + Html({nocache => 1}); + say '

Page unavailable

'; + } + Alert("Fatal error: $html."); + }; +} + sub showlink { my ($title, $href, $selected) = @_; return sprintf(