Mouse::Util::does_role() respects $thing->does() method
[gitmo/Mouse.git] / t / 300_immutable / 009_buildargs.t
1 #!/usr/bin/perl
2 # This is automatically generated by author/import-moose-test.pl.
3 # DO NOT EDIT THIS FILE. ANY CHANGES WILL BE LOST!!!
4 use t::lib::MooseCompat;
5
6 use strict;
7 use warnings;
8
9 use Test::More;
10
11 {
12     package Foo;
13     use Mouse;
14
15     has bar => ( is => "rw" );
16     has baz => ( is => "rw" );
17
18     sub BUILDARGS {
19         my ( $self, @args ) = @_;
20         unshift @args, "bar" if @args % 2 == 1;
21         return {@args};
22     }
23
24     __PACKAGE__->meta->make_immutable;
25
26     package Bar;
27     use Mouse;
28
29     extends qw(Foo);
30
31     __PACKAGE__->meta->make_immutable;
32 }
33
34 foreach my $class (qw(Foo Bar)) {
35     is( $class->new->bar, undef, "no args" );
36     is( $class->new( bar => 42 )->bar, 42, "normal args" );
37     is( $class->new( 37 )->bar, 37, "single arg" );
38     {
39         my $o = $class->new(bar => 42, baz => 47);
40         is($o->bar, 42, '... got the right bar');
41         is($o->baz, 47, '... got the right bar');
42     }
43     {
44         my $o = $class->new(42, baz => 47);
45         is($o->bar, 42, '... got the right bar');
46         is($o->baz, 47, '... got the right bar');
47     }
48 }
49
50 done_testing;