Skip Menu |

This queue is for tickets about the Type-Tiny CPAN distribution.

Report information
The Basics
Id: 86893
Status: resolved
Priority: 0/
Queue: Type-Tiny

People
Owner: Nobody in particular
Requestors: TIMB [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Clarify "may" in the docs in relation to using constraint => quote_sub q{...}
In https://metacpan.org/module/TOBYINK/Type-Tiny-0.014/lib/Type/Tiny/Manual/Libraries.pod#Inlining it says: "Note that defining a type constraint in terms of a constraint coderef and an inlining coderef can be a little repetitive. Sub::Quote provides an alternative that reduces repetition (though the inlined code might not be as compact/good/fast)." I'd really like to know more about this. Specifically: a) can it be as fast as inline_as for simple cases, like the one shown in the example? If not please explain document what the overhead is. b) If so, under what circumstances does it become slower and why?
Now, Types::Standard does not use Sub::Quote, but for the purposes of this explanation, let's assume that it does. The Object type constraint is a child of Ref, which is a child of Defined, which is a child of Item. The automatic inlining via Sub::Quote will always include the inlining for its parent. Therefore, the Sub::Quote inlining for Object would be something like: !!1 # inline check for Item && defined($_) # inline check for Defined && ref($_) # inline check for Ref && blessed($_) # inline check for Object Most of that is superfluous. Simply checking blessed($_) should be sufficient.
So to answer your questions more specifically, Sub::Quote-provided inlining will be slower if you have deep type constraint hierarchies, because it always checks every ancestor type. Inlining provided by inline_as has the option of not calling the parent type constraint's inlining code, and thus cutting down on the generated checks.
Better documentation in 0.015_04. I will close this bug when a new stable release is available on CPAN.