From e8e8d5a7167d69ba8ccc16dab1ab39c40899a5b8 Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Sat, 7 Feb 2015 16:02:28 +0100 Subject: [PATCH] common: ignore cookie set error 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 | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/common.inc.plp b/common.inc.plp index 21cbc0d..963b8a6 100644 --- a/common.inc.plp +++ b/common.inc.plp @@ -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]; -- 2.30.0