1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
package main;
our @args = qw(foo bar baz);
package WithMeta;
use Moose;
use MooseX::MultiInitArg;
has x => (
metaclass => 'MultiInitArg',
is => 'ro',
isa => 'Str',
init_args => \@main::args,
required => 1,
);
package WithTrait;
use Moose;
use MooseX::MultiInitArg;
has x => (
traits => ['MooseX::MultiInitArg::Trait'],
is => 'ro',
isa => 'Str',
init_args => \@main::args,
required => 1,
);
package main;
use Test::More tests => 10;
foreach my $class (qw(WithTrait WithMeta)) {
my $foo = $class->new(x => 'x');
is($foo->x, 'x', "$class x works");
foreach my $arg (@args)
{
my $x = $class->new($arg => $arg);
is($x->x, $arg, "$class $arg works.");
}
eval {my $fail = $class->new(x => 'y', foo => 'bar')};
ok($@, "Supplying more than one arg to $class causes death.");
}
|