X-Git-Url: http://git.shiar.nl/sheet.git/blobdiff_plain/d47666a5217b7c6274f8b76fe99027c2923d1d25..33e3013acbef27ba49fa091389ed8bf4096fa860:/common.inc.plp diff --git a/common.inc.plp b/common.inc.plp index 72a0eb8..c6b0c84 100644 --- a/common.inc.plp +++ b/common.inc.plp @@ -8,7 +8,12 @@ use open ':std' => ':utf8'; use File::stat 'stat'; use HTTP::Date; -use Shiar_Sheet::KeySigns qw(%sign); # dependant on $get{ascii} +use Shiar_Sheet::KeySigns qw(%sign); + +$PLP::ERROR = sub { + my ($text, $html) = @_; + print '

Fatal error: '.$html."

\n\n"; +}; our $style; our $showkeys = !exists $get{keys} ? undef : @@ -22,19 +27,21 @@ 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]; return join "\n", map { sprintf( '', - $_ eq $style ? 'stylesheet' : 'alternate stylesheet', "/$_.css", $_ + $_ eq $style ? 'stylesheet' : 'alternate stylesheet', "/$_.css?1.6", $_ ) } @_; } @@ -61,9 +68,10 @@ sub Html { # announce and check data modification checkmodified( $ENV{SCRIPT_FILENAME}, - (grep { /^Shiar_/ } values %INC), + (grep { /\bShiar_/ } values %INC), $meta->{data} ? @{ $meta->{data} } : (), ); + $header{'Cache-Control'} = sprintf 'max-age: ', 24*60*60; # default fallbacks $meta->{stylesheet} ||= [qw'light dark circus mono red terse']; @@ -76,7 +84,7 @@ sub Html { !$showkeys ? '' : $showkeys eq 'ghost' ? '' : (), - '', + '', ) if $meta->{keys}; # flatten arrays @@ -86,7 +94,6 @@ sub Html { ref $_ eq 'ARRAY' and $_ = stylesheet(@$_)."\n" for $meta->{stylesheet}; # other vars - my $sep = $meta->{charset} eq 'utf-8' ? '•' : ' -- '; my ($file) = $ENV{SCRIPT_FILENAME} =~ m{ ([^/]+) \.plp$ }x; # leading output @@ -111,11 +118,11 @@ EOT PLP_END { print <<"EOT";