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.
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
# 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;
--- /dev/null
+#!/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';
+