8 has bar => ( is => "rw" );
9 has baz => ( is => "rw" );
21 my ($class, $arg) = @_;
22 bless { attr => $arg }, $class;
25 sub attr { shift->{attr} }
27 package t::ext_non_moo::with_attr;
29 extends qw( t::non_moo );
31 has 'attr2' => ( is => 'ro' );
34 my ( $class, @args ) = @_;
35 shift @args if @args % 2 == 1;
45 has bar => ( is => "rw" );
46 has baz => ( is => "rw" );
49 my ( $class, @args ) = @_;
50 unshift @args, "bar" if @args % 2 == 1;
51 return $class->SUPER::BUILDARGS(@args);
64 has bar => ( is => "rw" );
65 has baz => ( is => "rw" );
67 around BUILDARGS => sub {
69 my ( $class, @args ) = @_;
71 unshift @args, "bar" if @args % 2 == 1;
73 return $class->$orig(@args);
82 foreach my $class (qw(Foo Bar Baz Biff)) {
83 is( $class->new->bar, undef, "no args" );
84 is( $class->new( bar => 42 )->bar, 42, "normal args" );
85 is( $class->new( 37 )->bar, 37, "single arg" );
87 my $o = $class->new(bar => 42, baz => 47);
88 is($o->bar, 42, '... got the right bar');
89 is($o->baz, 47, '... got the right baz');
92 my $o = $class->new(42, baz => 47);
93 is($o->bar, 42, '... got the right bar');
94 is($o->baz, 47, '... got the right baz');
98 foreach my $class (qw(Qux Quux)) {
99 my $o = $class->new(bar => 42, baz => 47);
100 is($o->bar, 42, '... got the right bar');
101 is($o->baz, 47, '... got the right baz');
106 like( $@, qr/Single parameters to new\(\) must be a HASH ref/,
107 "new() requires a list or a HASH ref"
111 $class->new( [ 37 ] );
113 like( $@, qr/Single parameters to new\(\) must be a HASH ref/,
114 "new() requires a list or a HASH ref"
118 $class->new( bar => 42, baz => 47, 'quux' );
120 like( $@, qr/You passed an odd number of arguments/,
121 "new() requires a list or a HASH ref"
125 my $non_moo = t::non_moo->new( 'bar' );
126 my $ext_non_moo = t::ext_non_moo::with_attr->new( 'bar', attr2 => 'baz' );
128 is $non_moo->attr, 'bar',
129 "non-moo accepts params";
130 is $ext_non_moo->attr, 'bar',
131 "extended non-moo passes params";
132 is $ext_non_moo->attr2, 'baz',
133 "extended non-moo has own attributes";