summaryrefslogtreecommitdiffstats
path: root/t/hashref-constructor.t
diff options
context:
space:
mode:
Diffstat (limited to 't/hashref-constructor.t')
-rw-r--r--t/hashref-constructor.t67
1 files changed, 67 insertions, 0 deletions
diff --git a/t/hashref-constructor.t b/t/hashref-constructor.t
new file mode 100644
index 0000000..00deff0
--- /dev/null
+++ b/t/hashref-constructor.t
@@ -0,0 +1,67 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Test::More;
+use Test::Fatal;
+
+{
+ 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;
+ is(exception { $baz = Baz->new( foo => 1, bar => 2, baz => 3 ) }, undef,
+ "constructor lives");
+ is($baz->foo, 1, "foo set");
+ is($baz->bar, 2, "bar set");
+ is($baz->baz, 3, "baz set");
+
+}
+
+{
+ my $baz;
+ is(exception { $baz = Baz->new({foo => 1, bar => 2, baz => 3}) }, undef,
+ "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;