From ea81da0f3d0ace97640a5579fd9755f08a92519b Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Mon, 9 May 2011 02:16:50 -0500 Subject: fix metaclass reinitialization --- lib/MooseX/NonMoose/Meta/Role/Class.pm | 19 +++++++++++++++++++ t/12-reinitialize.t | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 t/12-reinitialize.t diff --git a/lib/MooseX/NonMoose/Meta/Role/Class.pm b/lib/MooseX/NonMoose/Meta/Role/Class.pm index 579e618..e873877 100644 --- a/lib/MooseX/NonMoose/Meta/Role/Class.pm +++ b/lib/MooseX/NonMoose/Meta/Role/Class.pm @@ -54,6 +54,25 @@ has constructor_name => ( default => sub { shift->throw_error("No constructor name has been set") }, ); +# XXX ugh, really need to fix this in moose +around reinitialize => sub { + my $orig = shift; + my $class = shift; + my ($pkg) = @_; + + my $meta = blessed($pkg) ? $pkg : Class::MOP::class_of($pkg); + + $class->$orig( + @_, + (map { $_->init_arg => $_->get_value($meta) } + grep { $_->has_value($meta) } + map { $meta->meta->find_attribute_by_name($_) } + qw(has_nonmoose_constructor + has_nonmoose_destructor + constructor_name)), + ); +}; + sub _determine_constructor_options { my $self = shift; my @options = @_; diff --git a/t/12-reinitialize.t b/t/12-reinitialize.t new file mode 100644 index 0000000..5e4aa11 --- /dev/null +++ b/t/12-reinitialize.t @@ -0,0 +1,32 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use Test::More; +use Test::Fatal; + +{ + package Foo; + sub new { bless {}, shift } +} + +{ + package Foo::Meta::Role; + use Moose::Role; +} + +{ + package Foo::Sub; + use Moose; + use MooseX::NonMoose; + extends 'Foo'; + Moose::Util::MetaRole::apply_metaroles( + for => __PACKAGE__, + class_metaroles => { + class => ['Foo::Meta::Role'], + }, + ); + ::is(::exception { __PACKAGE__->meta->make_immutable }, undef, + "can make_immutable after reinitialization"); +} + +done_testing; -- cgit v1.2.3