common: catch cookie set failure
authorMischa POSLAWSKY <perl@shiar.org>
Sun, 8 Mar 2015 05:15:11 +0000 (06:15 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Tue, 9 Jun 2015 03:43:43 +0000 (05:43 +0200)
Sometimes creation causes a fatal error which should be ignored until fixed.

common.inc.plp

index ec6b0bf..563c0e4 100644 (file)
@@ -25,15 +25,16 @@ sub stylesheet {
 
        if (exists $get{style}) {
                $style = $styles{ $get{style} };
-               require CGI::Cookie;
-               if (my $cookie = CGI::Cookie->new(
-                       -name    => 'style',
-                       -value   => $style,
-                       -path    => '/',  # site-wide; current page is confusing to most users
-                       -expires => $style ? '+5y' : '-1d',
-               )) {
+               eval {
+                       require CGI::Cookie;
+                       my $cookie = CGI::Cookie->new(
+                               -name    => 'style',
+                               -value   => $style,
+                               -path    => '/',  # site-wide; current page is confusing to most users
+                               -expires => $style ? '+5y' : '-1d',
+                       ) or die "empty object returned\n";
                        AddCookie($cookie->as_string);
-               }
+               } or warn "Unable to create style cookie: $@";
        }
 
        $style ||= exists $cookie{style} && $styles{ $cookie{style} } || $_[0];