From 8bf5e6931a1bd96df0cdb1ceb94bbb3e578a8126 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Wed, 4 Sep 2013 19:38:21 -0400 Subject: packaging --- t/hashref-constructor.t | 67 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 t/hashref-constructor.t (limited to 't/hashref-constructor.t') 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; -- cgit v1.2.3-54-g00ecf