Moose Types Unconstrained

By Francis Sola (‎Hank‎) from Boston.pm
Lightning talk
Target audience: Any
Language: English
Tags: interfaces moose oo oop types


Moose type constraints are very useful and powerful.
However, if you are always using isa => $some_class in your type constraints, you are probably overly constraining yourself.

I will point out how using class names as type constraints is usually not in your best interest.
Perl supports "interface polymorphism" as opposed to "subtype polymorphism". As soon as you use a class name as a type constraint, you have unnecessarily limited yourself.

Prefer the use of roles as interfaces in Moose (does => $some_role) or in non-moose code, prefer $entity->can() checks as opposed to $entity->isa() checks.

The benefits become clear when using dependency injection and mock objects while testing.