From: Matt S Trout Date: Tue, 26 Jun 2012 18:16:14 +0000 (+0000) Subject: MooClass->meta X-Git-Tag: v0.091010~16 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=6e77b8df0c2c56f2b38212072011147950558848;p=gitmo%2FMoo.git MooClass->meta --- diff --git a/Changes b/Changes index cef0abb..206c656 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,4 @@ + - MooClass->meta - subconstructor handling for Moose classes 0.091009 - 2012-06-20 diff --git a/lib/Moo/HandleMoose.pm b/lib/Moo/HandleMoose.pm index 99dbf45..2de0c7b 100644 --- a/lib/Moo/HandleMoose.pm +++ b/lib/Moo/HandleMoose.pm @@ -30,6 +30,7 @@ sub maybe_reinject_fake_metaclass_for { sub inject_fake_metaclass_for { my ($name) = @_; require Class::MOP; + require Moo::HandleMoose::FakeMetaClass; Class::MOP::store_metaclass_by_name( $name, bless({ name => $name }, 'Moo::HandleMoose::FakeMetaClass') ); @@ -145,21 +146,4 @@ sub inject_real_metaclass_for { $meta; } -{ - package Moo::HandleMoose::FakeMetaClass; - - sub DESTROY { } - - sub AUTOLOAD { - my ($meth) = (our $AUTOLOAD =~ /([^:]+)$/); - Moo::HandleMoose::inject_real_metaclass_for((shift)->{name})->$meth(@_) - } - sub can { - Moo::HandleMoose::inject_real_metaclass_for((shift)->{name})->can(@_) - } - sub isa { - Moo::HandleMoose::inject_real_metaclass_for((shift)->{name})->isa(@_) - } -} - 1; diff --git a/lib/Moo/Object.pm b/lib/Moo/Object.pm index 9968382..421e7aa 100644 --- a/lib/Moo/Object.pm +++ b/lib/Moo/Object.pm @@ -69,4 +69,10 @@ sub does { goto &Role::Tiny::does_role; } +sub meta { + require Moo::HandleMoose::FakeMetaClass; + my $class = ref($_[0])||$_[0]; + bless({ name => $class }, 'Moo::HandleMoose::FakeMetaClass'); +} + 1; diff --git a/t/moo-accessors.t b/t/moo-accessors.t index 2b0f49e..5bb6b49 100644 --- a/t/moo-accessors.t +++ b/t/moo-accessors.t @@ -48,4 +48,7 @@ is_deeply( 'subclass with role ok' ); +ok(eval { Foo->meta->make_immutable }, 'make_immutable returns true'); +ok(!$INC{"Moose.pm"}, "Didn't load Moose"); + done_testing unless caller; diff --git a/xt/handle_moose.t b/xt/handle_moose.t index 3f6d39f..953b34a 100644 --- a/xt/handle_moose.t +++ b/xt/handle_moose.t @@ -15,6 +15,11 @@ is($attr->get_read_method_ref->body, Foo->can('one'), 'Right method'); is(Foo->new(one => 1, THREE => 3)->one, 1, 'Accessor still works'); +is( + Foo->meta->get_attribute('one')->get_read_method, 'one', + 'Method name via ->meta' +); + $meta = Moose::Meta::Class->initialize('Spoon'); $meta->superclasses('Moose::Object'); diff --git a/xt/moose-override-attribute-with-plus-syntax.t b/xt/moose-override-attribute-with-plus-syntax.t index e4b90c3..fb3c31e 100644 --- a/xt/moose-override-attribute-with-plus-syntax.t +++ b/xt/moose-override-attribute-with-plus-syntax.t @@ -21,6 +21,16 @@ use Test::Fatal; default => 'MooseChild', ); } +{ + package MooseChild2; + use Moose; + extends 'MooParent'; + + has '+foo' => ( + default => 'MooseChild2', + ); + __PACKAGE__->meta->make_immutable +} is( MooseChild->new->foo, @@ -28,5 +38,11 @@ is( 'default value in Moose child' ); +is( + MooseChild2->new->foo, + 'MooseChild2', + 'default value in Moose child' +); + done_testing;