How to have Moose return a child class instance instead of its own class, for polymorphism

Posted by alex8657 on Stack Overflow See other posts from Stack Overflow or by alex8657
Published on 2010-06-08T00:25:27Z Indexed on 2010/06/08 0:32 UTC
Read the original article Hit count: 436

Filed under:
|
|

I want to create a generic class, whose builder would not return an instance of this generic class, but an instance of a dedicated children class.

As Moose does automatic object building, i do not get to understand if this something possible, and how to create a Moose class with Moose syntax and having this behaviour

Eg: The user asks: $file = Repository->new(uri=>'sftp://blabla') .... and is returned an Repository::_Sftp instance

User would use $file as if it is a Repository instance, without the need to know the real subclass (polymorphism)

© Stack Overflow or respective owner

Related posts about perl

Related posts about polymorphism