MooseのTypeConstraintは,型というよりはあるデータの性質を表現したものだと考えられる。また,TypeCoercionは,ある型(=あるデータの性質)に対してフックを掛けるメカニズムと考えられる。 このように考えると,Coercionを利用していろいろと面白いことができるのではないかと思う。 たとえば,以下のようにCoercionを利用してエンコーディングを推測することができる*1。 #!perl package E; use Any::Moose; use Any::Moose '::Util::TypeConstraints'; use Encode qw(encode decode FB_QUIET); subtype 'UniStr', as 'Str', where { utf8::is_utf8($_) }; # define types represent a