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


In reply to How to create a parameterizable Type::Tiny constraint by Yary

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.