evalEmpire/Mite — pull request #37 by tobyink (2014-08-03 23:28:19+00:00)
Title: Type constraint checks

Here's a **very** rough cut at type constraint checks. **DO NOT MERGE THIS PULL REQUEST!!** I'm just creating the pull request so that it's on your radar.

The idea is to inline the Type::Tiny checks so that the compiled Mite class doesn't require Type::Tiny at all.

Currently the main problem with it is that, say, the check for `isa => "Object"` will be compiled to something like `Scalar::Util::blessed($var)`, but Type::Tiny doesn't have a way of indicating to Mite that it requires Scalar::Util to be loaded in order for this to work. The following is the list of potentially problematic type constraints in Types::Standard...

* `Object` (requires Scalar::Util)
* Parameterized versions of `Ref` (requires Scalar::Util)
* `RegexpRef` (requires re.pm)
* `ClassName` and `RoleName` (requires Types::Standard itself)
* `LaxNum` and `Num` (requires Scalar::Util)
* `FileHandle` (requires re.pm)
* `Object` (requires Scalar::Util), including any subtypes of `Object` such as class types, role types, duck types.
* `Overload` (requires Scalar::Util and overload.pm)
* `StrMatch` (it's complicated!)

Solving this is likely to require some changes to Type::Tiny - possibly some mechanism for Type::Tiny to indicate which modules it is relying on when it inlines some code. I'm unlikely to include that in the next release, but I'd certainly consider it further down the track.

Coercions are theoretically not much extra work.