c7c700cb87d18657d9a7d9d4926a94dfc4a0bafb
[gitmo/Mouse.git] / t / 300_immutable / 009_buildargs.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 14;
7
8 {
9     package Foo;
10     use Mouse;
11
12     has bar => ( is => "rw" );
13     has baz => ( is => "rw" );    
14
15     sub BUILDARGS {
16         my ( $self, @args ) = @_;
17         unshift @args, "bar" if @args % 2 == 1;
18         return {@args};
19     }
20
21     __PACKAGE__->meta->make_immutable;
22
23     package Bar;
24     use Mouse;
25
26     extends qw(Foo);
27     
28     __PACKAGE__->meta->make_immutable;
29 }
30
31 foreach my $class qw(Foo Bar) {
32     is( $class->new->bar, undef, "no args" );
33     is( $class->new( bar => 42 )->bar, 42, "normal args" );
34     SKIP: {
35         skip "this feature doesn't supported by Mouse", 1;
36         is( $class->new( 37 )->bar, 37, "single arg" );
37     };
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     SKIP: {
44         skip "this feature doesn't supported by Mouse", 2;
45         {
46             my $o = $class->new(42, baz => 47);
47             is($o->bar, 42, '... got the right bar');
48             is($o->baz, 47, '... got the right bar');
49         }    
50     };
51 }
52
53