Skip Menu |

This queue is for tickets about the MooseX-StrictConstructor CPAN distribution.

Report information
The Basics
Id: 52795
Status: resolved
Priority: 0/
Queue: MooseX-StrictConstructor

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

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



Subject: StrictConstructor + mutable + extends doesn't always dwim
The attached patch demonstrates the problem. Note that if I make the new classes in the patch (ExtendsObject, ExtendsStandard) immutable the new tests do pass. So this is a difference in mutable vs immutable behavior. Thanks, -Todd
Subject: patch.txt
diff --git a/t/basic.t b/t/basic.t index 24f62ce..ec00496 100644 --- a/t/basic.t +++ b/t/basic.t @@ -1,7 +1,7 @@ use strict; use warnings; -use Test::More tests => 15; +use Test::More tests => 17; { @@ -104,6 +104,27 @@ use Test::More tests => 15; __PACKAGE__->meta()->make_immutable(); } +{ + package ExtendsObject; + + use Moose; + use MooseX::StrictConstructor; + extends 'Moose::Object'; + + has 'thing' => ( is => 'rw' ); + no Moose; +# __PACKAGE__->meta()->make_immutable(); +} + +{ + package ExtendsStandard; + + use Moose; + use MooseX::StrictConstructor; + extends 'Standard'; + no Moose; +# __PACKAGE__->meta()->make_immutable(); +} eval { Standard->new( thing => 1, bad => 99 ) }; is( $@, '', 'standard Moose class ignores unknown params' ); @@ -158,3 +179,10 @@ is( $@, '', eval { ImmutableTricky->new( thing => 1, agent => 99 ) }; like( $@, qr/unknown attribute.+: agent/, 'ImmutableTricky still blows up on unknown params other than spy' ); + +eval { ExtendsObject->new( thing => 1, bad => 99 ) }; +like( $@, qr/unknown attribute.+: bad/, 'extending Moose::Object can still be strict' ); + +eval { ExtendsStandard->new( thing => 1, bad => 99 ) }; +like( $@, qr/unknown attribute.+: bad/, 'extending non-strict can still be strict' ); +
On Tue Dec 15 16:12:20 2009, THEPLER wrote: Show quoted text
> The attached patch demonstrates the problem. Note that if I make the > new classes in the patch (ExtendsObject, ExtendsStandard) immutable the > new tests do pass. So this is a difference in mutable vs immutable > behavior.
The bug is that the immutabilized classes are strict. When you call "extends" explicitly, you are explicitly replacing your existing parent class. MX::SC works by altering your parent class, so instead of extending Moose::Object, you extend a custom class which is Moose::Object plus our validating role. The immutable version works because of a weird side effect. I'm going to mark this ticket as resolved. If you have further questions, please email me the moose@perl.org list. Please don't respond to this ticket, as it will be re-opened.
One thing to add ... Arguably, this is a bug in Moose, because Moose should know that the default constructor has been altered, but I'm not sure we can fix that.