From 35a44de4f6d64502ac59b84b40d1034e143ade52 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Fri, 20 Aug 2010 12:57:58 -0500 Subject: fix edge case with inlined fallback constructors need to handle hashref parameters --- t/052-hashref-constructor.t | 67 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 t/052-hashref-constructor.t (limited to 't') diff --git a/t/052-hashref-constructor.t b/t/052-hashref-constructor.t new file mode 100644 index 0000000..74fd530 --- /dev/null +++ b/t/052-hashref-constructor.t @@ -0,0 +1,67 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use Test::More; +use Test::Exception; + +{ + package Foo; + + sub new { + my $class = shift; + bless { ref($_[0]) ? %{$_[0]} : @_ }, $class; + } + + sub foo { + my $self = shift; + $self->{foo}; + } +} + +{ + package Bar; + use Moose; + use MooseX::NonMoose; + + extends 'Foo'; + + has _bar => ( + init_arg => 'bar', + reader => 'bar', + ); + + __PACKAGE__->meta->make_immutable; +} + +{ + package Baz; + use Moose; + + extends 'Bar'; + + has _baz => ( + init_arg => 'baz', + reader => 'baz', + ); +} + +{ + my $baz; + lives_ok { $baz = Baz->new( foo => 1, bar => 2, baz => 3 ) } + "constructor lives"; + is($baz->foo, 1, "foo set"); + is($baz->bar, 2, "bar set"); + is($baz->baz, 3, "baz set"); + +} + +{ + my $baz; + lives_ok { $baz = Baz->new({foo => 1, bar => 2, baz => 3}) } + "constructor lives (hashref)"; + is($baz->foo, 1, "foo set (hashref)"); + is($baz->bar, 2, "bar set (hashref)"); + is($baz->baz, 3, "baz set (hashref)"); +} + +done_testing; -- cgit v1.2.3-54-g00ecf