X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMouse.git;a=blobdiff_plain;f=lib%2FMouse%2FUtil%2FTypeConstraints.pm;h=fc99aa87099620bcb318fcb0c0d9e073c8ac5678;hp=2b2d558c4f04efe7f795e1050a91661a6412a1cc;hb=ebe91068002fbe34a924a0a9e2cd79553867938c;hpb=aff73a9e6d34b45a21123586c0893921df98181b diff --git a/lib/Mouse/Util/TypeConstraints.pm b/lib/Mouse/Util/TypeConstraints.pm index 2b2d558..fc99aa8 100644 --- a/lib/Mouse/Util/TypeConstraints.pm +++ b/lib/Mouse/Util/TypeConstraints.pm @@ -11,7 +11,11 @@ Mouse::Exporter->setup_import_methods( as_is => [qw( as where message optimize_as from via - type subtype coerce class_type role_type enum + + type subtype class_type role_type duck_type + enum + coerce + find_type_constraint )], ); @@ -172,6 +176,22 @@ sub role_type { ); } +sub duck_type { + my($name, @methods); + + if(!(@_ == 1 && ref($_[0]) eq 'ARRAY')){ + $name = shift; + } + + @methods = (@_ == 1 && ref($_[0]) eq 'ARRAY') ? @{$_[0]} : @_; + + return _create_type 'type', $name => ( + optimized_as => Mouse::Util::generate_can_predicate_for(\@methods), + + type => 'DuckType', + ); +} + sub typecast_constraints { # DEPRECATED my($class, $pkg, $type, $value) = @_; Carp::croak("wrong arguments count") unless @_ == 4;