That is why BEGIN{} blocks were invented :)
BEGIN {
use MooseX::Declare;
class Foo {
use feature qw(say);
use Data::Dumper;
use MooseX::MultiMethods;
use MooseX::Types -declare => [qw(Bar MyStr MyNum)];
use MooseX::Types::Moose qw(Str Num);
use MooseX::Types::Structured qw(Dict);
BEGIN {
subtype MyStr,
as Str;
subtype MyNum,
as Num;
subtype Bar,
as Dict[
string => MyStr,
number => MyNum,
],
message { 'Invalid Foo struct' };
};
multi method baz(Bar $barrr) {
say'Bar';
say Dumper $barrr
}
multi method baz(Str $string) {
say 'Str';
say Dumper $string;
}
}
}
no Moose;
no MooseX::Declare;
1;
package main;
my $foo = Foo->new;
$foo->baz( { string => 'hello', number => 1.00, } );
$foo->baz( 'hello world' )