develooper Front page | perl.perl5.porters | Postings from December 2019

Re: Type and Value Constraints and Coercions

From:
Tony Cook
Date:
December 3, 2019 00:57
Subject:
Re: Type and Value Constraints and Coercions
Message ID:
20191203001914.ujz2jhbqob66exsb@mars.tony.develop-help.com
On Fri, Nov 29, 2019 at 10:18:57AM +0000, Toby Inkster (TOBYINK) wrote:
> This is a reply to Dave Mitchell's email, but it will probably get
> threaded badly as I've only just subscribed to perl5-porters and don't
> have the original email to click "reply" on.
> 
> 
> This is all pretty over-engineered. It can be simplified to something
> that would work well with existing type implementations such as
> MooseX::Types, MouseX::Types, Type::Tiny, and Specio.

If you haven't see them, Toby's blog postings on Type::Tiny are worth reading:

http://blogs.perl.org/mt/mt-search.fcgi?blog_id=1019&tag=Type-Tiny&limit=20

> Second, define these:
> 
>   use Scalar::Util;
>   sub UNIVERSAL::check {
>     my ($class, $object) = @_;
>     blessed($object) && !blessed($class) && $object->DOES($class);
>   }
>   sub UNIVERSAL::get_message {
>     my ($class, $value) = @_;
>     "$value is not $class";
>   }
> 
> Third, nothing. There is no third.

I think is should be distinct from isa, so I don't think the above is needed.

Tony



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About