First draf of MooseX manual page (just one more to go)
[gitmo/Moose.git] / t / 010_basics / 015_buildargs.t
CommitLineData
977a86ba 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use Test::More tests => 14;
7
8{
9 package Foo;
10 use Moose;
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 Bar;
22 use Moose;
23
24 extends qw(Foo);
25}
26
27foreach my $class qw(Foo Bar) {
28 is( $class->new->bar, undef, "no args" );
29 is( $class->new( bar => 42 )->bar, 42, "normal args" );
30 is( $class->new( 37 )->bar, 37, "single arg" );
31 {
32 my $o = $class->new(bar => 42, baz => 47);
33 is($o->bar, 42, '... got the right bar');
34 is($o->baz, 47, '... got the right bar');
35 }
36 {
37 my $o = $class->new(42, baz => 47);
38 is($o->bar, 42, '... got the right bar');
39 is($o->baz, 47, '... got the right bar');
40 }
41}
42
43