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

Matthew Somerville matthew at mysociety.org
Sat Jan 10 17:40:06 CET 2009


Petter Reinholdtsen wrote:
> 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. :)

Glad to hear it! So you're saying that Perl 5.10 changes fields::new() 
to bless the object itself? I haven't looked at 5.10 closely, we're 
still on 5.8. I guess the code is probably not using fields::new() 
correctly? It's rather old code in general.

ATB,
Matthew

> 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;
>  }


More information about the fiksgatami mailing list