[NUUG fiksgatami] [patch] Fix for strange perl error (Was: Stuck setting up our fixmystreet copy - strange error)

Petter Reinholdtsen pere at hungry.com
Sat Jan 10 17:05:25 CET 2009


[Petter Reinholdtsen]
> I do not understand what is going wrong here. :/

I finally was able to figure it out.  The bless() call was actually
failing, and the reason is that the $self variable is already blessed.
Did not know that double bless() would generate an error, but
apparently it does.  Some debug printing later, I finally figured it
out.  This patch solve the issue, and give me a working fixmystreet
front page.  Yay. :)

Index: mySociety/Web.pm
===================================================================
RCS file: /repos/mysociety/perllib/mySociety/Web.pm,v
retrieving revision 1.20
diff -u -r1.20 Web.pm
--- mySociety/Web.pm    27 Oct 2008 15:31:43 -0000      1.20
+++ mySociety/Web.pm    10 Jan 2009 16:04:47 -0000
@@ -57,7 +57,11 @@
     my $self = fields::new('mySociety::Web');
     $self->{q} = $q;
     $self->{scratch} = { };
-    return bless($self, $class);
+    if (ref($self) ne $class) {
+        # Bless $self unless fields::new already did bless it
+        return bless($self, $class);
+    }
+    return $self;
 }

 # q

Happy hacking,
-- 
Petter Reinholdtsen


More information about the fiksgatami mailing list