evalEmpire / Mite

Mite - A zero dependency, fast loading, Moose-like Perl module
Other
3 stars 1 forks source link

Type constraint checks #37

Closed tobyink closed 2 years ago

tobyink commented 10 years ago

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...

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.

tobyink commented 5 years ago

I guess Mite is pretty dead, but I've made it so:

local $Type::Tiny::AvoidCallbacks = 1;

... will tell Type::Tiny to generate code that can be used by standalone stuff like Mite, so it will generate inlined code that doesn't depend on Type::Tiny. It will still sometimes have callbacks to Scalar::Util though.