Support modifier by regexp
[gitmo/Mouse.git] / t / 300_immutable / 009_buildargs.t
CommitLineData
fc1d8369 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use Test::More tests => 14;
7
8{
9 package Foo;
b0000b3d 10 use Mouse;
fc1d8369 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;
b0000b3d 24 use Mouse;
fc1d8369 25
26 extends qw(Foo);
27
28 __PACKAGE__->meta->make_immutable;
29}
30
31foreach my $class qw(Foo Bar) {
32 is( $class->new->bar, undef, "no args" );
33 is( $class->new( bar => 42 )->bar, 42, "normal args" );
9dcd7d23 34 is( $class->new( 37 )->bar, 37, "single arg" );
35 my $o = $class->new(bar => 42, baz => 47);
36 is($o->bar, 42, '... got the right bar');
37 is($o->baz, 47, '... got the right bar');
38 my $ob = $class->new(42, baz => 47);
39 is($ob->bar, 42, '... got the right bar');
40 is($ob->baz, 47, '... got the right bar');
fc1d8369 41}
42
43