summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2010-06-15 00:53:14 -0500
committerJesse Luehrs <doy@tozt.net>2010-06-15 00:53:14 -0500
commit571bfa3b91ff5567338948776b6fce84d3ede09e (patch)
treedde0ee41847f846ac29174074a3c03079dcf329c
parent199626024f7087c05be3005965d33be2bb8a845f (diff)
downloadmoosex-nonmoose-571bfa3b91ff5567338948776b6fce84d3ede09e.tar.gz
moosex-nonmoose-571bfa3b91ff5567338948776b6fce84d3ede09e.zip
fix inlined nonmoose constructors which call other methods (woosley)
-rw-r--r--lib/MooseX/NonMoose/Meta/Role/Constructor.pm2
-rw-r--r--t/025-constructor-method-calls.t47
2 files changed, 48 insertions, 1 deletions
diff --git a/lib/MooseX/NonMoose/Meta/Role/Constructor.pm b/lib/MooseX/NonMoose/Meta/Role/Constructor.pm
index d0ececb..50ddec6 100644
--- a/lib/MooseX/NonMoose/Meta/Role/Constructor.pm
+++ b/lib/MooseX/NonMoose/Meta/Role/Constructor.pm
@@ -58,7 +58,7 @@ sub _generate_instance {
my $arglist = $meta->get_method('FOREIGNBUILDARGS')
? "${class_var}->FOREIGNBUILDARGS(\@_)"
: '@_';
- my $instance = "$super_new_class->$new($arglist)";
+ my $instance = "${class_var}->${super_new_class}::$new($arglist)";
return "my $var = $instance;\n"
. "if (!Scalar::Util::blessed($var)) {\n"
. " " . $self->_inline_throw_error(
diff --git a/t/025-constructor-method-calls.t b/t/025-constructor-method-calls.t
new file mode 100644
index 0000000..7806b44
--- /dev/null
+++ b/t/025-constructor-method-calls.t
@@ -0,0 +1,47 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Test::More;
+use Test::Moose qw(with_immutable);
+
+my ($foo, $foosub);
+{
+ package Foo;
+
+ sub new {
+ my $class = shift;
+ my $obj = bless {}, $class;
+ $obj->init;
+ $obj;
+ }
+
+ sub init {
+ $foo++
+ }
+}
+
+{
+ package Foo::Sub;
+ use base 'Foo';
+
+ sub init {
+ $foosub++;
+ shift->SUPER::init;
+ }
+}
+
+{
+ package Foo::Sub::Sub;
+ use Moose;
+ use MooseX::NonMoose;
+ extends 'Foo::Sub';
+}
+
+with_immutable {
+ ($foo, $foosub) = (0, 0);
+ Foo::Sub::Sub->new;
+ is($foo, 1, "Foo::init called");
+ is($foosub, 1, "Foo::Sub::init called");
+} 'Foo::Sub::Sub';
+
+done_testing;