common: ignore cookie set error
[sheet.git] / common.inc.plp
index 72a0eb8c438cd03175b8ed1d919700a9aca2fa17..963b8a6d1f4a8ef33a7685326c91ed8ae6163862 100644 (file)
@@ -8,7 +8,7 @@ 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);
 
 our $style;
 our $showkeys = !exists $get{keys} ? undef :
@@ -22,19 +22,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(
                '<link rel="%s" type="text/css" media="all" href="%s" title="%s">',
-               $_ eq $style ? 'stylesheet' : 'alternate stylesheet', "/$_.css", $_
+               $_ eq $style ? 'stylesheet' : 'alternate stylesheet', "/$_.css?1.6", $_
        ) } @_;
 }
 
@@ -61,9 +63,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 +79,7 @@ sub Html {
                !$showkeys ? '<style type="text/css"> .no {visibility:hidden} </style>'
                        : $showkeys eq 'ghost' ? '<style type="text/css"> .no, .alias {opacity:.5} </style>'
                        : (),
-               '<script type="text/javascript" src="/keys.js"></script>',
+               '<script type="text/javascript" src="/keys.js?1.6"></script>',
        ) if $meta->{keys};
 
        # flatten arrays
@@ -86,7 +89,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 +113,11 @@ EOT
        PLP_END {
                print <<"EOT";
 <p class="footer">
-       <a href="/" rel="home">sheet.shiar.nl</a>/$file.<a href="/source/$file.plp"
+       <a href="/" rel="start">sheet.shiar.nl</a>/$file.<a href="/source/$file.plp"
         rel="code" title="Written in Perl">plp</a>
        <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> $sep
+       created by <a href="http://shiar.nl/" rel="author">Shiar</a> $sign{sep}
        <a href="http://www.fsf.org/licensing/licenses/agpl-3.0.html" rel="copyright"
         title="Licensed under the GNU Affero General Public License, version 3">AGPLv3</a>
 </p>