summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2010-06-15 02:10:41 -0500
committerJesse Luehrs <doy@tozt.net>2010-06-15 02:12:08 -0500
commit93eab51bc542fed536c8b0a51a4ee3dbf82b53f4 (patch)
tree0abbf3599f9c0b2fdd9687a013fa259f81ad6a79
parent60c5f48aff6a579ce22bd4b4245f7be346609901 (diff)
downloadmoosex-nonmoose-93eab51bc542fed536c8b0a51a4ee3dbf82b53f4.tar.gz
moosex-nonmoose-93eab51bc542fed536c8b0a51a4ee3dbf82b53f4.zip
fallback constructor still needs to set __INSTANCE__ properly
-rw-r--r--dist.ini2
-rw-r--r--lib/MooseX/NonMoose/Meta/Role/Constructor.pm13
-rw-r--r--t/24-nonmoose-moose-nonmoose.t6
-rw-r--r--t/50-buggy-constructor-inlining.t2
4 files changed, 14 insertions, 9 deletions
diff --git a/dist.ini b/dist.ini
index 4338ca9..baff464 100644
--- a/dist.ini
+++ b/dist.ini
@@ -7,5 +7,5 @@ copyright_holder = Jesse Luehrs
dist = MooseX-NonMoose
[Prereq]
-Moose = 1.05
+Moose = 1.08
List::MoreUtils = 0
diff --git a/lib/MooseX/NonMoose/Meta/Role/Constructor.pm b/lib/MooseX/NonMoose/Meta/Role/Constructor.pm
index 38c70f0..4b3ee82 100644
--- a/lib/MooseX/NonMoose/Meta/Role/Constructor.pm
+++ b/lib/MooseX/NonMoose/Meta/Role/Constructor.pm
@@ -46,6 +46,19 @@ around can_be_inlined => sub {
return $self->$orig(@_);
};
+sub _generate_fallback_constructor {
+ my $self = shift;
+ my ($class_var) = @_;
+ my $new = $self->name;
+ my $meta = $self->associated_metaclass;
+ my $super_new_class = $meta->find_next_method_by_name($new)->package_name;
+ my $arglist = $meta->get_method('FOREIGNBUILDARGS')
+ ? "${class_var}->FOREIGNBUILDARGS(\@_)"
+ : '@_';
+ my $instance = "${class_var}->${super_new_class}::$new($arglist)";
+ "${class_var}->Moose::Object::new(__INSTANCE__ => $instance, \@_)"
+}
+
sub _generate_instance {
my $self = shift;
my ($var, $class_var) = @_;
diff --git a/t/24-nonmoose-moose-nonmoose.t b/t/24-nonmoose-moose-nonmoose.t
index faa6f6f..ef0ce88 100644
--- a/t/24-nonmoose-moose-nonmoose.t
+++ b/t/24-nonmoose-moose-nonmoose.t
@@ -68,10 +68,7 @@ Foo::Moose->meta->make_immutable;
$foo = Foo::Moose::Sub->new(name => 'foomoosesub', foo2 => 'FOO2');
isa_ok($foo, 'Foo');
isa_ok($foo, 'Foo::Moose');
-TODO: {
-local $TODO = 'nonmoose-moose-nonmoose inheritance doesn\'t quite work';
is($foo->foo, 'foomoosesub', 'got name from nonmoose constructor (immutable)');
-}
is($foo->foo2, 'FOO2', 'got attribute value from moose constructor (immutable)');
$foo = Foo::Moose->new(name => 'foomoosesub', foo2 => 'FOO2');
isa_ok($foo, 'Foo');
@@ -93,10 +90,7 @@ Bar::Moose->meta->make_immutable;
$bar = Bar::Moose::Sub->new(name => 'barmoosesub', bar2 => 'BAR2');
isa_ok($bar, 'Bar');
isa_ok($bar, 'Bar::Moose');
-TODO: {
-local $TODO = 'nonmoose-moose-nonmoose inheritance doesn\'t quite work';
is($bar->bar, 'barmoosesub', 'got name from nonmoose constructor (immutable)');
-}
is($bar->bar2, 'BAR2', 'got attribute value from moose constructor (immutable)');
$bar = Bar::Moose->new(name => 'barmoosesub', bar2 => 'BAR2');
isa_ok($bar, 'Bar');
diff --git a/t/50-buggy-constructor-inlining.t b/t/50-buggy-constructor-inlining.t
index 591fae0..c72c7c8 100644
--- a/t/50-buggy-constructor-inlining.t
+++ b/t/50-buggy-constructor-inlining.t
@@ -26,9 +26,7 @@ my ($Foo, $Bar, $Baz) = (0, 0, 0);
}
Baz->new;
-{ local $TODO = "need to call custom constructor for other classes, not Moose::Object->new";
is($Foo, 1, "Foo->new is called");
-}
{ local $TODO = "need to call non-Moose constructor, not superclass constructor";
is($Bar, 0, "Bar->new is not called");
}