X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fbuildargs.t;h=f1e4c2701b093096349bc07fb198589e682a4715;hb=c9a5dcbd2dab679f195484b996e0511bfdf47107;hp=1a541bdc752b1f52ea43399bd6708ad2f2518abd;hpb=a17be455d30de29a1979c1bececb5419ca3a672a;p=gitmo%2FMoo.git diff --git a/t/buildargs.t b/t/buildargs.t index 1a541bd..f1e4c27 100644 --- a/t/buildargs.t +++ b/t/buildargs.t @@ -13,6 +13,31 @@ use Test::More; extends qw(Qux); } + +{ + package t::non_moo; + + sub new { + my ($class, $arg) = @_; + bless { attr => $arg }, $class; + } + + sub attr { shift->{attr} } + + package t::ext_non_moo::with_attr; + use Moo; + extends qw( t::non_moo ); + + has 'attr2' => ( is => 'ro' ); + + sub BUILDARGS { + my ( $class, @args ) = @_; + shift @args if @args % 2 == 1; + return { @args }; + } +} + + { package Foo; use Moo; @@ -88,7 +113,25 @@ foreach my $class (qw(Qux Quux)) { like( $@, qr/Single parameters to new\(\) must be a HASH ref/, "new() requires a list or a HASH ref" ); + + eval { + $class->new( bar => 42, baz => 47, 'quux' ); + }; + like( $@, qr/You passed an odd number of arguments/, + "new() requires a list or a HASH ref" + ); } +my $non_moo = t::non_moo->new( 'bar' ); +my $ext_non_moo = t::ext_non_moo::with_attr->new( 'bar', attr2 => 'baz' ); + +is $non_moo->attr, 'bar', + "non-moo accepts params"; +is $ext_non_moo->attr, 'bar', + "extended non-moo passes params"; +is $ext_non_moo->attr2, 'baz', + "extended non-moo has own attributes"; + + done_testing;