パルカワ2

PerlとRubyとイチャラブ

Mouse::Util::TypeConstraintsのunion_type

http://cpansearch.perl.org/src/GFUJI/Mouse-2.1.0/t/040_type_constraints/009_union_types_and_coercions.t

subtype 'IO::StringOrFile' => as 'IO::String | IO::File';

だけで動くのかと勝手に思ってたけど、そうでもないようです。

    subtype 'IO::String'
        => as 'Object'
        => where { $_->isa('IO::String') };

    subtype 'IO::File'
        => as 'Object'
        => where { $_->isa('IO::File') };

    subtype 'IO::StringOrFile' => as 'IO::String | IO::File';