Yary has asked for the wisdom of the Perl Monks concerning the following question:

I was trying to create my own parameterizable type constraint in Type::Tiny, something like Row[`a] from MooseX::DBIx::Class::Type. The docs have this hint:
constraint_generator

Coderef that generates a new constraint coderef based on parameters. Alternatively, the constraint generator can return a fully-formed Type::Tiny object, in which case the name_generator, inline_generator, and coercion_generator attributes documented below are ignored.

Optional; providing a generator makes this type into a parameterizable type constraint.

And I don't quite get it, even while looking at the source for "Ref" in Types::Standard. I do understand that my type will need a constraint_generator coderef, and it can either return a closure that will do the constraint checking, or it can return a Type::Tiny object.

It seems like returning a Type::Tiny object is "easier", assuming one could re-use Ref from Types::Standard, but the semi-recursive nature of it is confusing me. Anyone care to post a working example of a custom parameterizable Type::Tiny constraint?

Edit OK, I admit it, I am really converting MooseX::DBIx::Class::Type to a Type::Tiny library, and am hung up on not using MooseX::Types::Parameterizable. I think I can figure it out...

  • Comment on How to create a parameterizable Type::Tiny constraint

Replies are listed 'Best First'.
Re: How to create a parameterizable Type::Tiny constraint
by Yary (Pilgrim) on Mar 16, 2015 at 17:56 UTC