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 ec6b0bf68ed6d3d8858d58500c13de3d59362cb1..563c0e48ba5bdfa8986592c91fb46f65d7287732 100644 (file)
@@ -25,15 +25,16 @@ sub stylesheet {
 
        if (exists $get{style}) {
                $style = $styles{ $get{style} };
 
        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);
                        AddCookie($cookie->as_string);
-               }
+               } or warn "Unable to create style cookie: $@";
        }
 
        $style ||= exists $cookie{style} && $styles{ $cookie{style} } || $_[0];
        }
 
        $style ||= exists $cookie{style} && $styles{ $cookie{style} } || $_[0];