Generate a string of Perl code that can be used to inline the type check into other functions. If your type check is being used within a Moose or Moo constructor or accessor methods, or used by Type::Params, this can lead to significant performance improvements.

Experimental: your inline_as block can return a list, in which case these will be smushed together with "&&". The first item on the list may be undef, in which case the undef will be replaced by the inlined parent type constraint. (And will throw an exception if there is no parent.)

Add coercions to the target type constraint. The list of coercions is a list of type constraint, conversion code pairs. Conversion code can be either a string of Perl code or a coderef; in either case the value to be converted is $_.

You should pretty much always use this when declaring an unattached coercion because it's exceedingly useful for a type coercion to know what it will coerce to - this allows it to skip coercion when no coercion is needed (e.g. avoiding coercing [] to [ [] ]) and allows assert_coerce to work properly.

Note that, for example, "42" satisfies Int, but it would satisfy the type constraints Num, Str, and Any as well. In this case, the classifier has picked the most specific type constraint that "42" satisfies.

If no type constraint is satisfied by the value, then the classifier will return undef.

Given a string like "ArrayRef[Int|CodeRef]", turns it into a type constraint object, hopefully doing what you mean.

It uses the syntax of Type::Parser. Firstly the Type::Registry for the caller package is consulted; if that doesn't have a match, Types::Standard is consulted for type constraint names; and if there's still no match, then if a type constraint looks like a class name, a new Type::Tiny::Class object is created for it.

Somewhere along the way, it also checks Moose/Mouse's type constraint registries if they are loaded.

You can specify an alternative for the caller using the for option. If you'd rather create a Type::Tiny::Role object, set the does option to true.

# An arrayref of objects, each of which must do role Foo.
my $type = dwim_type("ArrayRef[Foo]", does => 1);
Type::Registry->for_me->add_types("-Standard");
Type::Registry->for_me->alias_type("Int" => "Foo");
# An arrayref of integers.
my $type = dwim_type("ArrayRef[Foo]", does => 1);

While it's probably better overall to use the proper Type::Registry interface for resolving type constraint strings, this function often does what you want.

It should never die if it fails to find a type constraint (but may die if the type constraint string is syntactically malformed), preferring to return undef.