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 45 46 47 48 49 50 51 52 53 54 55 56
|
use strict;
use warnings;
use Test::More 0.96;
{
package Object;
use Moose;
with(
'MooseX::OneArgNew' => {
type => 'Int',
init_arg => 'size',
},
'MooseX::OneArgNew' => {
type => 'ArrayRef',
init_arg => 'nums',
},
);
has size => (is => 'ro', isa => 'Int');
has nums => (is => 'ro', isa => 'ArrayRef[Int]');
}
{
my $obj = Object->new(10);
isa_ok($obj, 'Object');
is($obj->size, 10, "one-arg-new worked");
}
{
my $obj = Object->new({ size => 10 });
isa_ok($obj, 'Object');
is($obj->size, 10, "hashref args to ->new worked");
}
{
my $obj = Object->new(size => 10);
isa_ok($obj, 'Object');
is($obj->size, 10, "pair args to ->new worked");
}
{
my $obj = Object->new([ 1, 2, 3 ]);
isa_ok($obj, 'Object');
is($obj->size, undef, 'no size after ->new([...])');
is_deeply($obj->nums, [1, 2, 3], "arrayref args to ->new worked");
}
{
my $obj = eval { Object->new('ten') };
my $err = $@;
ok(! $obj, "couldn't construct Object with non-{} non-Int single-arg new");
like($err, qr/parameters to new/, "...error message seems plausible");
}
done_testing;
|