X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F300_immutable%2F009_buildargs.t;fp=t%2F300_immutable%2F009_buildargs.t;h=6c1ca33d69825182e6a3defb29b3d0677feed3de;hb=fc1d8369f17d2d6a06ecdcb13199e1d4ecb2e53f;hp=0000000000000000000000000000000000000000;hpb=3c40a22570a1412a4c442f5c64a56d8c5a7e688c;p=gitmo%2FMouse.git diff --git a/t/300_immutable/009_buildargs.t b/t/300_immutable/009_buildargs.t new file mode 100644 index 0000000..6c1ca33 --- /dev/null +++ b/t/300_immutable/009_buildargs.t @@ -0,0 +1,47 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Test::More tests => 14; + +{ + package Foo; + use Moose; + + has bar => ( is => "rw" ); + has baz => ( is => "rw" ); + + sub BUILDARGS { + my ( $self, @args ) = @_; + unshift @args, "bar" if @args % 2 == 1; + return {@args}; + } + + __PACKAGE__->meta->make_immutable; + + package Bar; + use Moose; + + extends qw(Foo); + + __PACKAGE__->meta->make_immutable; +} + +foreach my $class qw(Foo Bar) { + is( $class->new->bar, undef, "no args" ); + is( $class->new( bar => 42 )->bar, 42, "normal args" ); + is( $class->new( 37 )->bar, 37, "single arg" ); + { + my $o = $class->new(bar => 42, baz => 47); + is($o->bar, 42, '... got the right bar'); + is($o->baz, 47, '... got the right bar'); + } + { + my $o = $class->new(42, baz => 47); + is($o->bar, 42, '... got the right bar'); + is($o->baz, 47, '... got the right bar'); + } +} + +