From: Dave Rolsky Date: Tue, 22 Jan 2008 00:18:39 +0000 (+0000) Subject: Moose 0.34 broke the ability to make a Meta class immutable. This is a X-Git-Tag: 0_35~6 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=475042d05d8012f79b55c4d389653997202075e4;p=gitmo%2FMoose.git Moose 0.34 broke the ability to make a Meta class immutable. This is a fix, though I'm not convinced it's the _right_ fix. An alternative might be to ensure that attributes for Moose meta classes are always Moose::Meta::Attribute objects instead of Class::MOP::Attribute objects. Regardless, the test I added should be useful in exploring alternative fixes. --- diff --git a/MANIFEST b/MANIFEST index b62baa0..8d0618a 100644 --- a/MANIFEST +++ b/MANIFEST @@ -166,6 +166,7 @@ t/200_examples/006_example_Protomoose.t t/200_examples/007_Child_Parent_attr_inherit.t t/300_immutable/001_immutable_moose.t t/300_immutable/002_apply_roles_to_immutable.t +t/300_immutable/003_immutable_meta_class.t t/400_moose_util/001_moose_util.t t/400_moose_util/002_moose_util_does_role.t t/400_moose_util/003_moose_util_search_class_by_role.t diff --git a/lib/Moose/Meta/Method/Constructor.pm b/lib/Moose/Meta/Method/Constructor.pm index 55bd4fe..29c6f2f 100644 --- a/lib/Moose/Meta/Method/Constructor.pm +++ b/lib/Moose/Meta/Method/Constructor.pm @@ -87,7 +87,13 @@ sub intialize_body { # to be picked up in the eval my $attrs = $self->attributes; - my @type_constraints = map { $_->type_constraint } @$attrs; + # We need to check if the attribute ->can('type_constraint') + # since we may be trying to immutabilize a Moose meta class, + # which in turn has attributes which are Class::MOP::Attribute + # objects, rather than + # Moose::Meta::Attribute. Class::MOP::Attribute attributes + # have no type constraints. + my @type_constraints = map { $_->type_constraint } grep { $_->can('type_constraint') } @$attrs; my @type_constraint_bodies = map { $_ && $_->_compiled_type_constraint; } @type_constraints; diff --git a/t/300_immutable/003_immutable_meta_class.t b/t/300_immutable/003_immutable_meta_class.t new file mode 100644 index 0000000..445702b --- /dev/null +++ b/t/300_immutable/003_immutable_meta_class.t @@ -0,0 +1,27 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Test::More tests => 2; +use Test::Exception; + +BEGIN { + use_ok('Moose'); +} + +{ + package My::Meta; + + use Moose; + + extends 'Moose::Meta::Class'; + + has 'meta_size' => + ( is => 'rw', + isa => 'Int', + ); +} + +lives_ok { My::Meta->meta()->make_immutable() } 'can make a meta class immutable'; +