updated dependents test
[gitmo/Moo.git] / t / foreignbuildargs.t
CommitLineData
336689b5 1use strictures 1;
2use Test::More;
3
4{
5 package t::non_moo_strict;
6
7 sub new {
8 my ($class, $arg) = @_;
9 die "invalid arguments: " . join(',', @_[2..$#_])
10 if @_ > 2;
11 bless { attr => $arg }, $class;
12 }
13
14 sub attr { shift->{attr} }
15
16 package t::ext_non_moo_strict::with_attr;
17 use Moo;
18 extends qw( t::non_moo_strict );
19
20 has 'attr2' => ( is => 'ro' );
21
22 sub FOREIGNBUILDARGS {
23 my ($class, %args) = @_;
24 return $args{attr};
25 }
85de1ef9 26
27 package t::ext_non_moo_strict::without_attr;
28 use Moo;
29 extends qw( t::non_moo_strict );
30
31 sub FOREIGNBUILDARGS {
32 my ($class, %args) = @_;
33 return $args{attr2};
34 }
336689b5 35}
36
37
38my $non_moo = t::non_moo_strict->new( 'bar' );
39my $ext_non_moo = t::ext_non_moo_strict::with_attr->new( attr => 'bar', attr2 => 'baz' );
85de1ef9 40my $ext_non_moo2 = t::ext_non_moo_strict::without_attr->new( attr => 'bar', attr2 => 'baz' );
336689b5 41
42is $non_moo->attr, 'bar',
43 "non-moo accepts params";
44is $ext_non_moo->attr, 'bar',
45 "extended non-moo passes params";
46is $ext_non_moo->attr2, 'baz',
47 "extended non-moo has own attributes";
85de1ef9 48is $ext_non_moo2->attr, 'baz',
49 "extended non-moo passes params";
336689b5 50
51
52done_testing;
53