Commit | Line | Data |
a136705d |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
a28e50e4 |
6 | use Test::More; |
a136705d |
7 | |
8 | { |
9 | package Foo; |
10 | use Moose; |
11 | |
12 | has bar => ( is => "rw" ); |
d03bd989 |
13 | has baz => ( is => "rw" ); |
a136705d |
14 | |
15 | sub BUILDARGS { |
16 | my ( $self, @args ) = @_; |
17 | unshift @args, "bar" if @args % 2 == 1; |
18 | return {@args}; |
19 | } |
20 | |
977a86ba |
21 | __PACKAGE__->meta->make_immutable; |
22 | |
a136705d |
23 | package Bar; |
24 | use Moose; |
25 | |
26 | extends qw(Foo); |
d03bd989 |
27 | |
a136705d |
28 | __PACKAGE__->meta->make_immutable; |
29 | } |
30 | |
643a8b19 |
31 | foreach my $class (qw(Foo Bar)) { |
a136705d |
32 | is( $class->new->bar, undef, "no args" ); |
33 | is( $class->new( bar => 42 )->bar, 42, "normal args" ); |
34 | is( $class->new( 37 )->bar, 37, "single arg" ); |
977a86ba |
35 | { |
36 | my $o = $class->new(bar => 42, baz => 47); |
37 | is($o->bar, 42, '... got the right bar'); |
38 | is($o->baz, 47, '... got the right bar'); |
39 | } |
40 | { |
41 | my $o = $class->new(42, baz => 47); |
42 | is($o->bar, 42, '... got the right bar'); |
43 | is($o->baz, 47, '... got the right bar'); |
d03bd989 |
44 | } |
a136705d |
45 | } |
977a86ba |
46 | |
a28e50e4 |
47 | done_testing; |