common: restyle fatal runtime errors
[sheet.git] / common.inc.plp
index 21cbc0d670a114cacdeeb5324963db7bb6d45170..c6b0c84f69909cbd2432a94328613b51b393fe52 100644 (file)
@@ -10,6 +10,11 @@ use File::stat 'stat';
 use HTTP::Date;
 use Shiar_Sheet::KeySigns qw(%sign);
 
+$PLP::ERROR = sub {
+       my ($text, $html) = @_;
+       print '<p class="error"><strong>Fatal error</strong>: '.$html."</p>\n\n";
+};
+
 our $style;
 our $showkeys = !exists $get{keys} ? undef :
        ($get{keys} ne '0' && ($get{keys} || 'always'));
@@ -22,12 +27,14 @@ sub stylesheet {
        if (exists $get{style}) {
                $style = $styles{ $get{style} };
                require CGI::Cookie;
-               AddCookie(CGI::Cookie->new(
+               if (my $cookie = CGI::Cookie->new(
                        -name    => 'style',
                        -value   => $style,
                        -path    => '/',  # site-wide; current page is confusing to most users
                        -expires => $style ? '+5y' : '-1d',
-               )->as_string);
+               )) {
+                       AddCookie($cookie->as_string);
+               }
        }
 
        $style ||= exists $cookie{style} && $styles{ $cookie{style} } || $_[0];