[Catalyst] Re: Moose/Object error in Catalyst
Dave Rolsky
autarch at urth.org
Wed Oct 13 21:02:23 GMT 2010
On Wed, 13 Oct 2010, Sir Robert Burbridge wrote:
> I notice that the relevant bit of Moose::Object (line 39 from the error y=
ou got) says:
> =A028 sub BUILDARGS {
> =A029=A0=A0=A0=A0 my $class =3D shift;
> =A030=A0=A0=A0=A0 if ( scalar @_ =3D=3D 1 ) {
> =A031=A0=A0=A0=A0=A0=A0=A0=A0 unless ( defined $_[0] && ref $_[0] e=
q 'HASH' ) {
> =A032=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 Class::MOP::class_of($cla=
ss)->throw_error(
> =A033=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 "Single param=
eters to new() must be a HASH ref",
> =A034=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 data =3D> $_[=
0] );
> =A035=A0=A0=A0=A0=A0=A0=A0=A0 }
> =A036=A0=A0=A0=A0=A0=A0=A0=A0 return { %{ $_[0] } };
> =A037=A0=A0=A0=A0 }
> =A038=A0=A0=A0=A0 else {
> =A039=A0=A0=A0=A0=A0=A0=A0=A0 return {@_};
> =A040=A0=A0=A0=A0 }
> =A041 }
> =
> Based on that, it looks like some object is trying to instantiate with an=
odd number of args, but not just one arg.=A0 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.=A0 Probably, it sh=
ould do something more like
> --- Object.old.pm=A0=A0=A0 2010-10-13 11:03:48.000000000 -0400
> +++ Object.new.pm=A0=A0=A0 2010-10-13 11:07:15.000000000 -0400
> @@ -35,9 +35,11 @@
> =A0=A0=A0=A0=A0=A0=A0=A0 }
> =A0=A0=A0=A0=A0=A0=A0=A0 return { %{ $_[0] } };
> =A0=A0=A0=A0 }
> -=A0=A0=A0 else {
> -=A0=A0=A0=A0=A0=A0=A0 return {@_};
> +=A0=A0=A0 elsif (scalar @_ % 2) {
> +=A0=A0=A0=A0=A0=A0=A0 warn "all args should be paired values (e.g.=
a=3D>1), not: @_";
> =A0=A0=A0=A0 }
> +=A0=A0=A0
> +=A0=A0=A0 return {@_};
> =A0}
> =A0
> =A0sub BUILDALL {
> =
> or maybe croak or something.
This seems like a reasonable idea. Would you mind discussing this on the =
Moose list (moose at perl.org) or in Moose IRC (irc://irc.perl.org/#moose). =
Or you can just send the patch to our RT queue, bug-moose at perl.org
Thanks,
-dave
/*=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
http://VegGuide.org http://blog.urth.org
Your guide to all that's veg House Absolute(ly Pointless)
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D*/
More information about the Catalyst
mailing list