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 57
|
use strict;
use warnings;
use Test::More tests => 6;
use Test::Fatal;
use MooseX::Traits; # for "no warnings ..."
{ package Trait;
use Moose::Role;
has 'foo' => (
is => 'ro',
isa => 'Str',
required => 1,
);
package Class;
use Moose;
with 'MooseX::Traits';
package Another::Trait;
use Moose::Role;
has 'bar' => (
is => 'ro',
isa => 'Str',
required => 1,
);
package Another::Class;
use Moose;
with 'MooseX::Traits';
has '+_trait_namespace' => ( default => 'Another' );
}
use MooseX::Traits::Util qw(new_class_with_traits);
isnt
exception { new_class_with_traits( 'OH NOES', 'Foo' ); },
undef,
' NOES is not a MX::Traits class';
isnt
exception { new_class_with_traits( 'Moose::Meta::Class', 'Foo' ); },
undef,
'Moose::Meta::Class is not a MX::Traits class';
my $class;
is
exception { $class = new_class_with_traits( 'Class' => 'Trait', 'Another::Trait' ); },
undef,
'new_class_with_traits works';
ok $class;
my $instance = $class->name->new( foo => '42', bar => '24' );
is $instance->foo, 42;
is $instance->bar, 24;
|