X-Git-Url: http://git.shiar.nl/sheet.git/blobdiff_plain/d22e7febda8720bc38069f7061adb43b98143c48..917ba679115b9e3cd7b88f7e5081a1a2503a684e:/common.inc.plp diff --git a/common.inc.plp b/common.inc.plp index e3316fc..7788049 100644 --- a/common.inc.plp +++ b/common.inc.plp @@ -20,6 +20,20 @@ sub Alert { say "
$body
\n"; } +sub Abort { + my ($html, $code, $debug) = @_; + unless ($PLP::sentheaders) { + $header{Status} = $code || 500; + } + elsif ($Dev) { + ref $html eq 'ARRAY' or $html = [$html]; + push @{$html}, "Also failed to set HTTP status $code" + . " after output!"; + } + Alert($html, $debug); + exit; +} + BEGIN { require Time::HiRes; our $Time = [Time::HiRes::gettimeofday()]; @@ -132,36 +146,38 @@ sub Html { '', ) if $meta->{keys}; - # leading output - say ''; - say ''; - say ''; - say ''; - say sprintf '', $_ - for $header{content_type}; - say sprintf '%s', $meta->{title}; - say sprintf '', EscapeHTML($_) - for join(' ', @{ $meta->{description} }) || (); - say sprintf '', EscapeHTML($_) - for join(', ', @{ $meta->{keywords} }) || (); - say ''; - say ''; - say for map { @{$_} } $meta->{raw} || (); - say '' if $Dev; - say ''; - say ''; - say sprintf '', $file; - - # development version indicator - printf '

beta

', join('; ', - 'position: fixed', - 'right: 1em', - 'opacity: .5', - 'border: 1ex solid red', - 'border-width: 1ex 0', - 'z-index: 1', - 'background: inherit', - ) if $Dev; + PLP_START { + # leading output + say ''; + say ''; + say ''; + say ''; + say sprintf '', $_ + for $header{content_type}; + say sprintf '%s', $meta->{title}; + say sprintf '', EscapeHTML($_) + for join(' ', @{ $meta->{description} }) || (); + say sprintf '', EscapeHTML($_) + for join(', ', @{ $meta->{keywords} }) || (); + say ''; + say ''; + say for map { @{$_} } $meta->{raw} || (); + say '' if $Dev; + say ''; + say ''; + say sprintf '', $file; + + # development version indicator + printf '

beta

', join('; ', + 'position: fixed', + 'right: 1em', + 'opacity: .5', + 'border: 1ex solid red', + 'border-width: 1ex 0', + 'z-index: 1', + 'background: inherit', + ) if $Dev; + }; # prepare trailing output PLP_END {