[Catalyst] Re: Moose/Object error in Catalyst

Sir Robert Burbridge rburbrid at cisco.com
Wed Oct 13 15:10:59 GMT 2010


On 10/01/2010 02:06 PM, Gavin Aiken wrote:
>>
>> [Thu Sep 30 19:57:59 2010] [warn] [client 208.93.49.4] mod_fcgid: =

>> stderr: Odd number of elements in anonymous hash at =

>> /usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/Moose/Object.=
pm =

>> line 39.
>>
>>
>> Any ideas what is causing it? I've tried to debug it but haven't =

>> managed to figure it out myself yet. If I roll back to the previous =

>> version of the table classes without the Moose stuff the error goes =

>> away - but I don't want to do that!
>
> I just discovered that if I keep the Moose stuff at the top of the =

> table classes, but comment out the line:
>
> __PACKAGE__->meta->make_immutable;
>
> at the bottom of all of them, the "Odd number of elements" error stops =

> happening. I still don't know why, or if this is a BAD THING to do - =

> if anyone can offer any advice I'd be grateful.
>
> ps I've posted this to the Catalyst list rather than DBIx::Class, =

> because I can use the Moose-ified schema outside of Catalyst without =

> getting any errors. I'm not sure if this really is therefore a =

> Catalyst error, but as that's the only place I see the error it seemed =

> like the best place to start asking for help.
>
> _______________________________________________
> List: Catalyst at lists.scsys.co.uk
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive: =

> http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
> Dev site: http://dev.catalyst.perl.org/
I know this is a little late, but it may be of some small use:

I notice that the relevant bit of Moose::Object (line 39 from the error =

you got) says:

      28 sub BUILDARGS {
      29     my $class =3D shift;
      30     if ( scalar @_ =3D=3D 1 ) {
      31         unless ( defined $_[0] && ref $_[0] eq 'HASH' ) {
      32             Class::MOP::class_of($class)->throw_error(
      33                 "Single parameters to new() must be a HASH ref",
      34                 data =3D> $_[0] );
      35         }
      36         return { %{ $_[0] } };
      37     }
      38     else {
    * 39         return {@_};*
      40     }
      41 }

Based on that, it looks like some object is trying to instantiate with =

an odd number of args, but not just one arg.  Something like

    my $obj =3D My::Awesome::Moose::Class->new(a=3D>1, b=3D>2, 'c');

The check in line 30 checks if there was just one arg.  Probably, it =

should do something more like

    --- Object.old.pm    2010-10-13 11:03:48.000000000 -0400
    +++ Object.new.pm    2010-10-13 11:07:15.000000000 -0400
    @@ -35,9 +35,11 @@
              }
              return { %{ $_[0] } };
          }
    -    else {
    -        return {@_};
    +    elsif (scalar @_ % 2) {
    +        warn "all args should be paired values (e.g. a=3D>1), not: @_";
          }
    +
    +    return {@_};
      }

      sub BUILDALL {

or maybe croak or something.

-Sir



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20101013/bb187=
8fd/attachment.htm


More information about the Catalyst mailing list