common: ignore cookie set error
authorMischa POSLAWSKY <perl@shiar.org>
Sat, 7 Feb 2015 15:02:28 +0000 (16:02 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Mon, 9 Feb 2015 19:29:47 +0000 (20:29 +0100)
Creating a CGI::Cookie object will fail if given an undefined value, causing
a fatal error trying to stringify and add it:
> Can't call method "as_string" on an undefined value

common.inc.plp

index 21cbc0d670a114cacdeeb5324963db7bb6d45170..963b8a6d1f4a8ef33a7685326c91ed8ae6163862 100644 (file)
@@ -22,12 +22,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];