I want to create a generic class, whose builder would not return an instance of this generic class, but an instance of a dedicated child class.
As Moose does automat
No (not directly). In general in Moose, calling CLASS->new where CLASS isa Moose::Object will return an instance of CLASS.
Can you describe in more detail what you are trying to achieve, and why you think this is what you want? You probably want to build a factory class -- when you call a method on it, it will call the appropriate class's constructor and return that object to you, without you having to be concerned with the particular type you get back:
package MyApp::Factory::Repository;
sub getFactory
{
my ($class, %attrs);
# figure out what the caller wants, and decide what type to return
$class ||= 'Repository::_Sftp';
return $class->new(attr1 => 'foo', attr2 => 'bar', %attrs);
}
my $file = MyApp::Factory::Repository->getFactory(uri=>'sftp://blabla');