Merge 'inline_wrapped_constructor' into 'trunk'
[gitmo/Moose.git] / t / 300_immutable / 009_buildargs.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More 'no_plan';
7
8 {
9     package Foo;
10     use Moose;
11
12     has bar => ( is => "rw" );
13
14     sub BUILDARGS {
15         my ( $self, @args ) = @_;
16         unshift @args, "bar" if @args % 2 == 1;
17         return {@args};
18     }
19
20     package Bar;
21     use Moose;
22
23     extends qw(Foo);
24
25     __PACKAGE__->meta->make_immutable;
26 }
27
28 foreach my $class qw(Foo Bar) {
29     is( $class->new->bar, undef, "no args" );
30     is( $class->new( bar => 42 )->bar, 42, "normal args" );
31     is( $class->new( 37 )->bar, 37, "single arg" );
32 }