Add built local::lib
[catagits/Gitalist.git] / local-lib5 / man / man3 / Moose::Util::TypeConstraints.3pm
diff --git a/local-lib5/man/man3/Moose::Util::TypeConstraints.3pm b/local-lib5/man/man3/Moose::Util::TypeConstraints.3pm
new file mode 100644 (file)
index 0000000..5d2efe1
--- /dev/null
@@ -0,0 +1,676 @@
+.\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.3
+.\"
+.\" Standard preamble:
+.\" ========================================================================
+.de Sh \" Subsection heading
+.br
+.if t .Sp
+.ne 5
+.PP
+\fB\\$1\fR
+.PP
+..
+.de Sp \" Vertical space (when we can't use .PP)
+.if t .sp .5v
+.if n .sp
+..
+.de Vb \" Begin verbatim text
+.ft CW
+.nf
+.ne \\$1
+..
+.de Ve \" End verbatim text
+.ft R
+.fi
+..
+.\" Set up some character translations and predefined strings.  \*(-- will
+.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
+.\" double quote, and \*(R" will give a right double quote.  | will give a
+.\" real vertical bar.  \*(C+ will give a nicer C++.  Capital omega is used to
+.\" do unbreakable dashes and therefore won't be available.  \*(C` and \*(C'
+.\" expand to `' in nroff, nothing in troff, for use with C<>.
+.tr \(*W-|\(bv\*(Tr
+.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
+.ie n \{\
+.    ds -- \(*W-
+.    ds PI pi
+.    if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
+.    if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\"  diablo 12 pitch
+.    ds L" ""
+.    ds R" ""
+.    ds C` ""
+.    ds C' ""
+'br\}
+.el\{\
+.    ds -- \|\(em\|
+.    ds PI \(*p
+.    ds L" ``
+.    ds R" ''
+'br\}
+.\"
+.\" If the F register is turned on, we'll generate index entries on stderr for
+.\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index
+.\" entries marked with X<> in POD.  Of course, you'll have to process the
+.\" output yourself in some meaningful fashion.
+.if \nF \{\
+.    de IX
+.    tm Index:\\$1\t\\n%\t"\\$2"
+..
+.    nr % 0
+.    rr F
+.\}
+.\"
+.\" For nroff, turn off justification.  Always turn off hyphenation; it makes
+.\" way too many mistakes in technical documents.
+.hy 0
+.if n .na
+.\"
+.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
+.\" Fear.  Run.  Save yourself.  No user-serviceable parts.
+.    \" fudge factors for nroff and troff
+.if n \{\
+.    ds #H 0
+.    ds #V .8m
+.    ds #F .3m
+.    ds #[ \f1
+.    ds #] \fP
+.\}
+.if t \{\
+.    ds #H ((1u-(\\\\n(.fu%2u))*.13m)
+.    ds #V .6m
+.    ds #F 0
+.    ds #[ \&
+.    ds #] \&
+.\}
+.    \" simple accents for nroff and troff
+.if n \{\
+.    ds ' \&
+.    ds ` \&
+.    ds ^ \&
+.    ds , \&
+.    ds ~ ~
+.    ds /
+.\}
+.if t \{\
+.    ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
+.    ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
+.    ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
+.    ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
+.    ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
+.    ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
+.\}
+.    \" troff and (daisy-wheel) nroff accents
+.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
+.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
+.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
+.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
+.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
+.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
+.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
+.ds ae a\h'-(\w'a'u*4/10)'e
+.ds Ae A\h'-(\w'A'u*4/10)'E
+.    \" corrections for vroff
+.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
+.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
+.    \" for low resolution devices (crt and lpr)
+.if \n(.H>23 .if \n(.V>19 \
+\{\
+.    ds : e
+.    ds 8 ss
+.    ds o a
+.    ds d- d\h'-1'\(ga
+.    ds D- D\h'-1'\(hy
+.    ds th \o'bp'
+.    ds Th \o'LP'
+.    ds ae ae
+.    ds Ae AE
+.\}
+.rm #[ #] #H #V #F C
+.\" ========================================================================
+.\"
+.IX Title "Moose::Util::TypeConstraints 3"
+.TH Moose::Util::TypeConstraints 3 "2009-11-19" "perl v5.8.7" "User Contributed Perl Documentation"
+.SH "NAME"
+Moose::Util::TypeConstraints \- Type constraint system for Moose
+.SH "SYNOPSIS"
+.IX Header "SYNOPSIS"
+.Vb 1
+\&  use Moose::Util::TypeConstraints;
+.Ve
+.PP
+.Vb 3
+\&  subtype 'Natural'
+\&      => as 'Int'
+\&      => where { $_ > 0 };
+.Ve
+.PP
+.Vb 4
+\&  subtype 'NaturalLessThanTen'
+\&      => as 'Natural'
+\&      => where { $_ < 10 }
+\&      => message { "This number ($_) is not less than ten!" };
+.Ve
+.PP
+.Vb 3
+\&  coerce 'Num'
+\&      => from 'Str'
+\&        => via { 0+$_ };
+.Ve
+.PP
+.Vb 1
+\&  enum 'RGBColors' => qw(red green blue);
+.Ve
+.PP
+.Vb 1
+\&  no Moose::Util::TypeConstraints;
+.Ve
+.SH "DESCRIPTION"
+.IX Header "DESCRIPTION"
+This module provides Moose with the ability to create custom type
+constraints to be used in attribute definition.
+.Sh "Important Caveat"
+.IX Subsection "Important Caveat"
+This is \fB\s-1NOT\s0\fR a type system for Perl 5. These are type constraints,
+and they are not used by Moose unless you tell it to. No type
+inference is performed, expressions are not typed, etc. etc. etc.
+.PP
+A type constraint is at heart a small \*(L"check if a value is valid\*(R"
+function. A constraint can be associated with an attribute. This
+simplifies parameter validation, and makes your code clearer to read,
+because you can refer to constraints by name.
+.Sh "Slightly Less Important Caveat"
+.IX Subsection "Slightly Less Important Caveat"
+It is \fBalways\fR a good idea to quote your type names.
+.PP
+This prevents Perl from trying to execute the call as an indirect
+object call. This can be an issue when you have a subtype with the
+same name as a valid class.
+.PP
+For instance:
+.PP
+.Vb 1
+\&  subtype DateTime => as Object => where { $_\->isa('DateTime') };
+.Ve
+.PP
+will \fIjust work\fR, while this:
+.PP
+.Vb 2
+\&  use DateTime;
+\&  subtype DateTime => as Object => where { $_\->isa('DateTime') };
+.Ve
+.PP
+will fail silently and cause many headaches. The simple way to solve
+this, as well as future proof your subtypes from classes which have
+yet to have been created, is to quote the type name:
+.PP
+.Vb 2
+\&  use DateTime;
+\&  subtype 'DateTime' => as 'Object' => where { $_\->isa('DateTime') };
+.Ve
+.Sh "Default Type Constraints"
+.IX Subsection "Default Type Constraints"
+This module also provides a simple hierarchy for Perl 5 types, here is
+that hierarchy represented visually.
+.PP
+.Vb 21
+\&  Any
+\&  Item
+\&      Bool
+\&      Maybe[`a]
+\&      Undef
+\&      Defined
+\&          Value
+\&              Str
+\&                  Num
+\&                      Int
+\&                  ClassName
+\&                  RoleName
+\&          Ref
+\&              ScalarRef
+\&              ArrayRef[`a]
+\&              HashRef[`a]
+\&              CodeRef
+\&              RegexpRef
+\&              GlobRef
+\&                  FileHandle
+\&              Object
+.Ve
+.PP
+\&\fB\s-1NOTE:\s0\fR Any type followed by a type parameter \f(CW\*(C`[`a]\*(C'\fR can be
+parameterized, this means you can say:
+.PP
+.Vb 3
+\&  ArrayRef[Int]    # an array of integers
+\&  HashRef[CodeRef] # a hash of str to CODE ref mappings
+\&  Maybe[Str]       # value may be a string, may be undefined
+.Ve
+.PP
+If Moose finds a name in brackets that it does not recognize as an
+existing type, it assumes that this is a class name, for example
+\&\f(CW\*(C`ArrayRef[DateTime]\*(C'\fR.
+.PP
+\&\fB\s-1NOTE:\s0\fR Unless you parameterize a type, then it is invalid to include
+the square brackets. I.e. \f(CW\*(C`ArrayRef[]\*(C'\fR will be treated as a new type
+name, \fInot\fR as a parameterization of \f(CW\*(C`ArrayRef\*(C'\fR.
+.PP
+\&\fB\s-1NOTE:\s0\fR The \f(CW\*(C`Undef\*(C'\fR type constraint for the most part works
+correctly now, but edge cases may still exist, please use it
+sparingly.
+.PP
+\&\fB\s-1NOTE:\s0\fR The \f(CW\*(C`ClassName\*(C'\fR type constraint does a complex package
+existence check. This means that your class \fBmust\fR be loaded for this
+type constraint to pass.
+.PP
+\&\fB\s-1NOTE:\s0\fR The \f(CW\*(C`RoleName\*(C'\fR constraint checks a string is a \fIpackage
+name\fR which is a role, like \f(CW'MyApp::Role::Comparable'\fR.
+.Sh "Type Constraint Naming"
+.IX Subsection "Type Constraint Naming"
+Type name declared via this module can only contain alphanumeric
+characters, colons (:), and periods (.).
+.PP
+Since the types created by this module are global, it is suggested
+that you namespace your types just as you would namespace your
+modules. So instead of creating a \fIColor\fR type for your
+\&\fBMy::Graphics\fR module, you would call the type
+\&\fIMy::Graphics::Types::Color\fR instead.
+.Sh "Use with Other Constraint Modules"
+.IX Subsection "Use with Other Constraint Modules"
+This module can play nicely with other constraint modules with some
+slight tweaking. The \f(CW\*(C`where\*(C'\fR clause in types is expected to be a
+\&\f(CW\*(C`CODE\*(C'\fR reference which checks it's first argument and returns a
+boolean. Since most constraint modules work in a similar way, it
+should be simple to adapt them to work with Moose.
+.PP
+For instance, this is how you could use it with
+Declare::Constraints::Simple to declare a completely new type.
+.PP
+.Vb 7
+\&  type 'HashOfArrayOfObjects',
+\&      {
+\&      where => IsHashRef(
+\&          \-keys   => HasLength,
+\&          \-values => IsArrayRef(IsObject)
+\&      )
+\&  };
+.Ve
+.PP
+For more examples see the \fIt/200_examples/004_example_w_DCS.t\fR test
+file.
+.PP
+Here is an example of using Test::Deep and it's non-test
+related \f(CW\*(C`eq_deeply\*(C'\fR function.
+.PP
+.Vb 8
+\&  type 'ArrayOfHashOfBarsAndRandomNumbers'
+\&      => where {
+\&          eq_deeply($_,
+\&              array_each(subhashof({
+\&                  bar           => isa('Bar'),
+\&                  random_number => ignore()
+\&              })))
+\&        };
+.Ve
+.PP
+For a complete example see the
+\&\fIt/200_examples/005_example_w_TestDeep.t\fR test file.
+.SH "FUNCTIONS"
+.IX Header "FUNCTIONS"
+.Sh "Type Constraint Constructors"
+.IX Subsection "Type Constraint Constructors"
+The following functions are used to create type constraints.  They
+will also register the type constraints your create in a global
+registry that is used to look types up by name.
+.PP
+See the \s-1SYNOPSIS\s0 for an example of how to use these.
+.IP "\fBsubtype 'Name' => as 'Parent' => where { } ...\fR" 4
+.IX Item "subtype 'Name' => as 'Parent' => where { } ..."
+This creates a named subtype.
+.Sp
+If you provide a parent that Moose does not recognize, it will
+automatically create a new class type constraint for this name.
+.Sp
+When creating a named type, the \f(CW\*(C`subtype\*(C'\fR function should either be
+called with the sugar helpers (\f(CW\*(C`where\*(C'\fR, \f(CW\*(C`message\*(C'\fR, etc), or with a
+name and a hashref of parameters:
+.Sp
+.Vb 1
+\& subtype( 'Foo', { where => ..., message => ... } );
+.Ve
+.Sp
+The valid hashref keys are \f(CW\*(C`as\*(C'\fR (the parent), \f(CW\*(C`where\*(C'\fR, \f(CW\*(C`message\*(C'\fR,
+and \f(CW\*(C`optimize_as\*(C'\fR.
+.IP "\fBsubtype as 'Parent' => where { } ...\fR" 4
+.IX Item "subtype as 'Parent' => where { } ..."
+This creates an unnamed subtype and will return the type
+constraint meta\-object, which will be an instance of
+Moose::Meta::TypeConstraint.
+.Sp
+When creating an anonymous type, the \f(CW\*(C`subtype\*(C'\fR function should either
+be called with the sugar helpers (\f(CW\*(C`where\*(C'\fR, \f(CW\*(C`message\*(C'\fR, etc), or with
+just a hashref of parameters:
+.Sp
+.Vb 1
+\& subtype( { where => ..., message => ... } );
+.Ve
+.IP "\fBclass_type ($class, ?$options)\fR" 4
+.IX Item "class_type ($class, ?$options)"
+Creates a new subtype of \f(CW\*(C`Object\*(C'\fR with the name \f(CW$class\fR and the
+metaclass Moose::Meta::TypeConstraint::Class.
+.IP "\fBrole_type ($role, ?$options)\fR" 4
+.IX Item "role_type ($role, ?$options)"
+Creates a \f(CW\*(C`Role\*(C'\fR type constraint with the name \f(CW$role\fR and the
+metaclass Moose::Meta::TypeConstraint::Role.
+.IP "\fBmaybe_type ($type)\fR" 4
+.IX Item "maybe_type ($type)"
+Creates a type constraint for either \f(CW\*(C`undef\*(C'\fR or something of the
+given type.
+.IP "\fBduck_type ($name, \e@methods)\fR" 4
+.IX Item "duck_type ($name, @methods)"
+This will create a subtype of Object and test to make sure the value
+\&\f(CW\*(C`can()\*(C'\fR do the methods in \f(CW\*(C`\e@methods\*(C'\fR.
+.Sp
+This is intended as an easy way to accept non-Moose objects that
+provide a certain interface. If you're using Moose classes, we
+recommend that you use a \f(CW\*(C`requires\*(C'\fR\-only Role instead.
+.IP "\fBduck_type (\e@methods)\fR" 4
+.IX Item "duck_type (@methods)"
+If passed an \s-1ARRAY\s0 reference as the only parameter instead of the
+\&\f(CW$name\fR, \f(CW\*(C`\e@methods\*(C'\fR pair, this will create an unnamed duck type.
+This can be used in an attribute definition like so:
+.Sp
+.Vb 4
+\&  has 'cache' => (
+\&      is  => 'ro',
+\&      isa => duck_type( [qw( get_set )] ),
+\&  );
+.Ve
+.IP "\fBenum ($name, \e@values)\fR" 4
+.IX Item "enum ($name, @values)"
+This will create a basic subtype for a given set of strings.
+The resulting constraint will be a subtype of \f(CW\*(C`Str\*(C'\fR and
+will match any of the items in \f(CW\*(C`\e@values\*(C'\fR. It is case sensitive.
+See the \s-1SYNOPSIS\s0 for a simple example.
+.Sp
+\&\fB\s-1NOTE:\s0\fR This is not a true proper enum type, it is simply
+a convenient constraint builder.
+.IP "\fBenum (\e@values)\fR" 4
+.IX Item "enum (@values)"
+If passed an \s-1ARRAY\s0 reference as the only parameter instead of the
+\&\f(CW$name\fR, \f(CW\*(C`\e@values\*(C'\fR pair, this will create an unnamed enum. This
+can then be used in an attribute definition like so:
+.Sp
+.Vb 4
+\&  has 'sort_order' => (
+\&      is  => 'ro',
+\&      isa => enum([qw[ ascending descending ]]),
+\&  );
+.Ve
+.IP "\fBas 'Parent'\fR" 4
+.IX Item "as 'Parent'"
+This is just sugar for the type constraint construction syntax.
+.Sp
+It takes a single argument, which is the name of a parent type.
+.IP "\fBwhere { ... }\fR" 4
+.IX Item "where { ... }"
+This is just sugar for the type constraint construction syntax.
+.Sp
+It takes a subroutine reference as an argument. When the type
+constraint is tested, the reference is run with the value to be tested
+in \f(CW$_\fR. This reference should return true or false to indicate
+whether or not the constraint check passed.
+.IP "\fBmessage { ... }\fR" 4
+.IX Item "message { ... }"
+This is just sugar for the type constraint construction syntax.
+.Sp
+It takes a subroutine reference as an argument. When the type
+constraint fails, then the code block is run with the value provided
+in \f(CW$_\fR. This reference should return a string, which will be used in
+the text of the exception thrown.
+.IP "\fBoptimize_as { ... }\fR" 4
+.IX Item "optimize_as { ... }"
+This can be used to define a \*(L"hand optimized\*(R" version of your
+type constraint which can be used to avoid traversing a subtype
+constraint hierarchy.
+.Sp
+\&\fB\s-1NOTE:\s0\fR You should only use this if you know what you are doing,
+all the built in types use this, so your subtypes (assuming they
+are shallow) will not likely need to use this.
+.IP "\fBtype 'Name' => where { } ...\fR" 4
+.IX Item "type 'Name' => where { } ..."
+This creates a base type, which has no parent.
+.Sp
+The \f(CW\*(C`type\*(C'\fR function should either be called with the sugar helpers
+(\f(CW\*(C`where\*(C'\fR, \f(CW\*(C`message\*(C'\fR, etc), or with a name and a hashref of
+parameters:
+.Sp
+.Vb 1
+\&  type( 'Foo', { where => ..., message => ... } );
+.Ve
+.Sp
+The valid hashref keys are \f(CW\*(C`where\*(C'\fR, \f(CW\*(C`message\*(C'\fR, and \f(CW\*(C`optimize_as\*(C'\fR.
+.Sh "Type Constraint Utilities"
+.IX Subsection "Type Constraint Utilities"
+.ie n .IP "\fBmatch_on_type \fB$value\fB => ( \f(BI$type\fB => \e&action, ... ?\e&default )\fR" 4
+.el .IP "\fBmatch_on_type \f(CB$value\fB => ( \f(CB$type\fB => \e&action, ... ?\e&default )\fR" 4
+.IX Item "match_on_type $value => ( $type => &action, ... ?&default )"
+This is a utility function for doing simple type based dispatching similar to
+match/case in O'Caml and case/of in Haskell. It is not as featureful as those
+languages, nor does not it support any kind of automatic destructuring
+bind. Here is a simple Perl pretty printer dispatching over the core Moose
+types.
+.Sp
+.Vb 26
+\&  sub ppprint {
+\&      my $x = shift;
+\&      match_on_type $x => (
+\&          HashRef => sub {
+\&              my $hash = shift;
+\&              '{ '
+\&                  . (
+\&                  join ", " => map { $_ . ' => ' . ppprint( $hash\->{$_} ) }
+\&                      sort keys %$hash
+\&                  ) . ' }';
+\&          },
+\&          ArrayRef => sub {
+\&              my $array = shift;
+\&              '[ ' . ( join ", " => map { ppprint($_) } @$array ) . ' ]';
+\&          },
+\&          CodeRef   => sub {'sub { ... }'},
+\&          RegexpRef => sub { 'qr/' . $_ . '/' },
+\&          GlobRef   => sub { '*' . B::svref_2object($_)\->NAME },
+\&          Object    => sub { $_\->can('to_string') ? $_\->to_string : $_ },
+\&          ScalarRef => sub { '\e\e' . ppprint( ${$_} ) },
+\&          Num       => sub {$_},
+\&          Str       => sub { '"' . $_ . '"' },
+\&          Undef     => sub {'undef'},
+\&          => sub { die "I don't know what $_ is" }
+\&      );
+\&  }
+.Ve
+.Sp
+Or a simple \s-1JSON\s0 serializer:
+.Sp
+.Vb 22
+\&  sub to_json {
+\&      my $x = shift;
+\&      match_on_type $x => (
+\&          HashRef => sub {
+\&              my $hash = shift;
+\&              '{ '
+\&                  . (
+\&                  join ", " =>
+\&                      map { '"' . $_ . '" : ' . to_json( $hash\->{$_} ) }
+\&                      sort keys %$hash
+\&                  ) . ' }';
+\&          },
+\&          ArrayRef => sub {
+\&              my $array = shift;
+\&              '[ ' . ( join ", " => map { to_json($_) } @$array ) . ' ]';
+\&          },
+\&          Num   => sub {$_},
+\&          Str   => sub { '"' . $_ . '"' },
+\&          Undef => sub {'null'},
+\&          => sub { die "$_ is not acceptable json type" }
+\&      );
+\&  }
+.Ve
+.Sp
+The matcher is done by mapping a \f(CW$type\fR to an \f(CW\*(C`\e&action\*(C'\fR. The \f(CW$type\fR can
+be either a string type or a Moose::Meta::TypeConstraint object, and
+\&\f(CW\*(C`\e&action\*(C'\fR is a subroutine reference. This function will dispatch on the
+first match for \f(CW$value\fR. It is possible to have a catch-all by providing an
+additional subroutine reference as the final argument to \f(CW\*(C`match_on_type\*(C'\fR.
+.Sh "Type Coercion Constructors"
+.IX Subsection "Type Coercion Constructors"
+You can define coercions for type constraints, which allow you to
+automatically transform values to something valid for the type
+constraint. If you ask your accessor to coerce, then Moose will run
+the type-coercion code first, followed by the type constraint
+check. This feature should be used carefully as it is very powerful
+and could easily take off a limb if you are not careful.
+.PP
+See the \s-1SYNOPSIS\s0 for an example of how to use these.
+.IP "\fBcoerce 'Name' => from 'OtherName' => via { ... }\fR" 4
+.IX Item "coerce 'Name' => from 'OtherName' => via { ... }"
+This defines a coercion from one type to another. The \f(CW\*(C`Name\*(C'\fR argument
+is the type you are coercing \fIto\fR.
+.IP "\fBfrom 'OtherName'\fR" 4
+.IX Item "from 'OtherName'"
+This is just sugar for the type coercion construction syntax.
+.Sp
+It takes a single type name (or type object), which is the type being
+coerced \fIfrom\fR.
+.IP "\fBvia { ... }\fR" 4
+.IX Item "via { ... }"
+This is just sugar for the type coercion construction syntax.
+.Sp
+It takes a subroutine reference. This reference will be called with
+the value to be coerced in \f(CW$_\fR. It is expected to return a new value
+of the proper type for the coercion.
+.Sh "Creating and Finding Type Constraints"
+.IX Subsection "Creating and Finding Type Constraints"
+These are additional functions for creating and finding type
+constraints. Most of these functions are not available for
+importing. The ones that are importable as specified.
+.IP "\fBfind_type_constraint($type_name)\fR" 4
+.IX Item "find_type_constraint($type_name)"
+This function can be used to locate the Moose::Meta::TypeConstraint
+object for a named type.
+.Sp
+This function is importable.
+.IP "\fBregister_type_constraint($type_object)\fR" 4
+.IX Item "register_type_constraint($type_object)"
+This function will register a Moose::Meta::TypeConstraint with the
+global type registry.
+.Sp
+This function is importable.
+.IP "\fBnormalize_type_constraint_name($type_constraint_name)\fR" 4
+.IX Item "normalize_type_constraint_name($type_constraint_name)"
+This method takes a type constraint name and returns the normalized
+form. This removes any whitespace in the string.
+.ie n .IP "\fBcreate_type_constraint_union($pipe_separated_types | \fB@type_constraint_names\fB)\fR" 4
+.el .IP "\fBcreate_type_constraint_union($pipe_separated_types | \f(CB@type_constraint_names\fB)\fR" 4
+.IX Item "create_type_constraint_union($pipe_separated_types | @type_constraint_names)"
+This can take a union type specification like \f(CW'Int|ArrayRef[Int]'\fR,
+or a list of names. It returns a new
+Moose::Meta::TypeConstraint::Union object.
+.IP "\fBcreate_parameterized_type_constraint($type_name)\fR" 4
+.IX Item "create_parameterized_type_constraint($type_name)"
+Given a \f(CW$type_name\fR in the form of \f(CW'BaseType[ContainerType]'\fR,
+this will create a new Moose::Meta::TypeConstraint::Parameterized
+object. The \f(CW\*(C`BaseType\*(C'\fR must exist already exist as a parameterizable
+type.
+.ie n .IP "\fBcreate_class_type_constraint($class, \fB$options\fB)\fR" 4
+.el .IP "\fBcreate_class_type_constraint($class, \f(CB$options\fB)\fR" 4
+.IX Item "create_class_type_constraint($class, $options)"
+Given a class name this function will create a new
+Moose::Meta::TypeConstraint::Class object for that class name.
+.Sp
+The \f(CW$options\fR is a hash reference that will be passed to the
+Moose::Meta::TypeConstraint::Class constructor (as a hash).
+.ie n .IP "\fBcreate_role_type_constraint($role, \fB$options\fB)\fR" 4
+.el .IP "\fBcreate_role_type_constraint($role, \f(CB$options\fB)\fR" 4
+.IX Item "create_role_type_constraint($role, $options)"
+Given a role name this function will create a new
+Moose::Meta::TypeConstraint::Role object for that role name.
+.Sp
+The \f(CW$options\fR is a hash reference that will be passed to the
+Moose::Meta::TypeConstraint::Role constructor (as a hash).
+.ie n .IP "\fBcreate_enum_type_constraint($name, \fB$values\fB)\fR" 4
+.el .IP "\fBcreate_enum_type_constraint($name, \f(CB$values\fB)\fR" 4
+.IX Item "create_enum_type_constraint($name, $values)"
+Given a enum name this function will create a new
+Moose::Meta::TypeConstraint::Enum object for that enum name.
+.ie n .IP "\fBcreate_duck_type_constraint($name, \fB$methods\fB)\fR" 4
+.el .IP "\fBcreate_duck_type_constraint($name, \f(CB$methods\fB)\fR" 4
+.IX Item "create_duck_type_constraint($name, $methods)"
+Given a duck type name this function will create a new
+Moose::Meta::TypeConstraint::DuckType object for that enum name.
+.IP "\fBfind_or_parse_type_constraint($type_name)\fR" 4
+.IX Item "find_or_parse_type_constraint($type_name)"
+Given a type name, this first attempts to find a matching constraint
+in the global registry.
+.Sp
+If the type name is a union or parameterized type, it will create a
+new object of the appropriate, but if given a \*(L"regular\*(R" type that does
+not yet exist, it simply returns false.
+.Sp
+When given a union or parameterized type, the member or base type must
+already exist.
+.Sp
+If it creates a new union or parameterized type, it will add it to the
+global registry.
+.IP "\fBfind_or_create_isa_type_constraint($type_name)\fR" 4
+.IX Item "find_or_create_isa_type_constraint($type_name)"
+.PD 0
+.IP "\fBfind_or_create_does_type_constraint($type_name)\fR" 4
+.IX Item "find_or_create_does_type_constraint($type_name)"
+.PD
+These functions will first call \f(CW\*(C`find_or_parse_type_constraint\*(C'\fR. If
+that function does not return a type, a new anonymous type object will
+be created.
+.Sp
+The \f(CW\*(C`isa\*(C'\fR variant will use \f(CW\*(C`create_class_type_constraint\*(C'\fR and the
+\&\f(CW\*(C`does\*(C'\fR variant will use \f(CW\*(C`create_role_type_constraint\*(C'\fR.
+.IP "\fBget_type_constraint_registry\fR" 4
+.IX Item "get_type_constraint_registry"
+Returns the Moose::Meta::TypeConstraint::Registry object which
+keeps track of all type constraints.
+.IP "\fBlist_all_type_constraints\fR" 4
+.IX Item "list_all_type_constraints"
+This will return a list of type constraint names in the global
+registry. You can then fetch the actual type object using
+\&\f(CW\*(C`find_type_constraint($type_name)\*(C'\fR.
+.IP "\fBlist_all_builtin_type_constraints\fR" 4
+.IX Item "list_all_builtin_type_constraints"
+This will return a list of builtin type constraints, meaning those
+which are defined in this module. See the \*(L"Default Type Constraints\*(R"
+section for a complete list.
+.IP "\fBexport_type_constraints_as_functions\fR" 4
+.IX Item "export_type_constraints_as_functions"
+This will export all the current type constraints as functions into
+the caller's namespace (\f(CW\*(C`Int()\*(C'\fR, \f(CW\*(C`Str()\*(C'\fR, etc). Right now, this is
+mostly used for testing, but it might prove useful to others.
+.IP "\fBget_all_parameterizable_types\fR" 4
+.IX Item "get_all_parameterizable_types"
+This returns all the parameterizable types that have been registered,
+as a list of type objects.
+.IP "\fBadd_parameterizable_type($type)\fR" 4
+.IX Item "add_parameterizable_type($type)"
+Adds \f(CW$type\fR to the list of parameterizable types
+.SH "BUGS"
+.IX Header "BUGS"
+All complex software has bugs lurking in it, and this module is no
+exception. If you find a bug please either email me, or add the bug
+to cpan\-RT.
+.SH "AUTHOR"
+.IX Header "AUTHOR"
+Stevan Little <stevan@iinteractive.com>
+.SH "COPYRIGHT AND LICENSE"
+.IX Header "COPYRIGHT AND LICENSE"
+Copyright 2006\-2009 by Infinity Interactive, Inc.
+.PP
+<http://www.iinteractive.com>
+.PP
+This library is free software; you can redistribute it and/or modify
+it under the same terms as Perl itself.