Skip Menu |

This queue is for tickets about the Moose CPAN distribution.

Report information
The Basics
Id: 94585
Status: stalled
Priority: 0/
Queue: Moose

People
Owner: Nobody in particular
Requestors: MITHALDU [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: useless error message on moose attribute when parent class constructor made an object not based on a hash reference
This error message: Not a HASH reference at (eval 188)[C:/Perl/lib/Eval/Closure.pm:125] line 9. Comes from this code: { package NonHashref; sub new { bless [], shift } } { package NonHashref::Subclassed; use Moose; extends "NonHashref"; has thing => ( is => 'rw', default => sub { 1 } ); } like exception { NonHashref::Subclassed->new->thing }, qr/Constructor of parent class of NonHashref::Subclassed returned an object based on ARRAY.*extends-non-moo/, 'non-hashref constructor in parent class results in useful error message'; Currently the same issue is being discussed in Moo: https://github.com/moose/Moo/pull/5
Subject: Re: [rt.cpan.org #94585] useless error message on moose attribute when parent class constructor made an object not based on a hash reference
Date: Wed, 9 Apr 2014 16:41:24 -0700
To: Christian Walde via RT <bug-Moose [...] rt.cpan.org>
From: Karen Etheridge <ether [...] cpan.org>
On Wed, Apr 09, 2014 at 07:34:06PM -0400, Christian Walde via RT wrote: Show quoted text
> This error message: > > Not a HASH reference at (eval 188)[C:/Perl/lib/Eval/Closure.pm:125] line 9. > > Comes from this code: > > { > package NonHashref; > sub new { bless [], shift } > } > { > package NonHashref::Subclassed; > use Moose; > extends "NonHashref"; > has thing => ( is => 'rw', default => sub { 1 } ); > }
This isn't valid code -- when extending a non-moose class, you need to use MooseX::NonMoose in the child. At that point, I think failure to handle non-hashref-based objects falls on MooseX::NonMoose to handle (or reject with a sensible error message).
I do not care if the code can work or not, i know it cannot. It is code that can be reasonably expected to be written and has a useless error message. Further, if in fact it is an absolute requirement for Moose to use MooseX::NonMoose for non-Moose extension, then Moose currently still fails to check for this and inform the developer.
Subject: Re: [rt.cpan.org #94585] useless error message on moose attribute when parent class constructor made an object not based on a hash reference
Date: Wed, 9 Apr 2014 16:59:55 -0700
To: Christian Walde via RT <bug-Moose [...] rt.cpan.org>
From: Karen Etheridge <ether [...] cpan.org>
On Wed, Apr 09, 2014 at 07:46:28PM -0400, Christian Walde via RT wrote: Show quoted text
> I do not care if the code can work or not, i know it cannot. It is code that can be reasonably expected to be written and has a useless error message. > Further, if in fact it is an absolute requirement for Moose to use MooseX::NonMoose for non-Moose extension, then Moose currently still fails to check for this and inform the developer.
I agree, the error message is not terribly enlightening. I suspect it's better for a non-Moose hashref-based object though, and that the arrayref part is interfering. But we can surely clean that up.
I started looking into this and it's obvious how to fix it. Unlike Moo, we don't actually install a constructor in every class, so in the absence of immutabilization the only new() method that gets called is the one from the parent class. We can't inline the subclass constructor anyway, since it doesn't inherit from Moose::Object. The only place left to check for this sort of stuff is in the accessor methods themselves, but I don't think we want the overhead of checking the object's reftype on every access!
CC: ;
Subject: Re: [rt.cpan.org #94585] useless error message on moose attribute when parent class constructor made an object not based on a hash reference
Date: Sun, 3 Aug 2014 19:05:10 -0400
To: Dave Rolsky via RT <bug-Moose [...] rt.cpan.org>
From: Jesse Luehrs <doy [...] tozt.net>
For what it's worth, it's absolutely not a requirement to use MooseX::NonMoose when extending a non-Moose class. There is quite a bit of code in the wild that relies on this (it was always the case that Moose was written to be used with existing code, but MooseX::NonMoose wasn't written for quite some time after Moose was). -doy