+ - MooClass->meta
- subconstructor handling for Moose classes
0.091009 - 2012-06-20
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')
);
$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;
goto &Role::Tiny::does_role;
}
+sub meta {
+ require Moo::HandleMoose::FakeMetaClass;
+ my $class = ref($_[0])||$_[0];
+ bless({ name => $class }, 'Moo::HandleMoose::FakeMetaClass');
+}
+
1;
'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;
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');
default => 'MooseChild',
);
}
+{
+ package MooseChild2;
+ use Moose;
+ extends 'MooParent';
+
+ has '+foo' => (
+ default => 'MooseChild2',
+ );
+ __PACKAGE__->meta->make_immutable
+}
is(
MooseChild->new->foo,
'default value in Moose child'
);
+is(
+ MooseChild2->new->foo,
+ 'MooseChild2',
+ 'default value in Moose child'
+);
+
done_testing;