From: Graham Knop Date: Fri, 22 Feb 2013 09:58:44 +0000 (-0500) Subject: test for FOREIGNBUILDARGS X-Git-Tag: v1.001000~24 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=336689b561b9ba9a53ae53c74a0fec556eefd774;p=gitmo%2FMoo.git test for FOREIGNBUILDARGS --- diff --git a/t/foreignbuildargs.t b/t/foreignbuildargs.t new file mode 100644 index 0000000..291bd57 --- /dev/null +++ b/t/foreignbuildargs.t @@ -0,0 +1,41 @@ +use strictures 1; +use Test::More; + +{ + package t::non_moo_strict; + + sub new { + my ($class, $arg) = @_; + die "invalid arguments: " . join(',', @_[2..$#_]) + if @_ > 2; + bless { attr => $arg }, $class; + } + + sub attr { shift->{attr} } + + package t::ext_non_moo_strict::with_attr; + use Moo; + extends qw( t::non_moo_strict ); + + has 'attr2' => ( is => 'ro' ); + + sub FOREIGNBUILDARGS { + my ($class, %args) = @_; + return $args{attr}; + } +} + + +my $non_moo = t::non_moo_strict->new( 'bar' ); +my $ext_non_moo = t::ext_non_moo_strict::with_attr->new( attr => 'bar', attr2 => 'baz' ); + +is $non_moo->attr, 'bar', + "non-moo accepts params"; +is $ext_non_moo->attr, 'bar', + "extended non-moo passes params"; +is $ext_non_moo->attr2, 'baz', + "extended non-moo has own attributes"; + + +done_testing; +