From your choices, $obj->meta->name->new() or (blessed $obj)->new() are the safest.
Implemented implementation methods, you create an anonymous subclass and apply roles to this subclass and restart the instance in this subclass. This means that any of these solutions will work perfectly with features. Perl does not have truly anonymous subclasses (each package must have a namespace), Moose works around this, creating a name in a common namespace for anonymous classes.
If you took a second to try the sample code, you will see it in action.
$perl -Moose -E'with q[MooseX::Traits]; package Role; use Moose::Role; package main; say Class->with_traits(q[Role])->new->meta->name' MooseX::Traits::__ANON__::SERIAL::1
Hope this helps.
perigrin
source share