.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.42) .\" .\" Standard preamble: .\" ======================================================================== .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. \*(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- .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" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "MooX::Types::MooseLike 3pm" .TH MooX::Types::MooseLike 3pm "2022-06-16" "perl v5.34.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" MooX::Types::MooseLike \- some Moosish types and a type builder .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 4 \& package MyApp::Types; \& use MooX::Types::MooseLike; \& use base qw(Exporter); \& our @EXPORT_OK = (); \& \& # Define some types \& my $defs = [{ \& name => \*(AqMyType\*(Aq, \& test => sub { predicate($_[0]) }, \& message => sub { "$_[0] is not the type we want!" } \& }, \& { \& name => \*(AqVarChar\*(Aq, \& test => sub { \& my ($value, $param) = @_; \& length($value) <= $param; \& }, \& message => sub { "$_[0] is too large! It should be less than or equal to $_[1]." } \& }]; \& \& # Make the types available \- this adds them to @EXPORT_OK automatically. \& MooX::Types::MooseLike::register_types($defs, _\|_PACKAGE_\|_); \& \& ... \& \& # Somewhere in code that uses the type \& package MyApp::Foo; \& use Moo; \& use MyApp::Types qw(MyType VarChar); \& \& has attribute => ( \& is => \*(Aqro\*(Aq, \& isa => MyType, \& ); \& \& has string => ( \& is => \*(Aqro\*(Aq, \& isa => VarChar[25] \& ); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This module provides a possibility to build your own set of Moose-like types. These custom types can then be used to describe fields in Moo-based classes. .PP See MooX::Types::MooseLike::Base for a list of available base types. Its source also provides an example of how to build base types, along with both parameterizable and non-parameterizable. .SH "FUNCTIONS" .IX Header "FUNCTIONS" .SS "register_types" .IX Subsection "register_types" \&\fBregister_types( types, package, moose_namespace )\fR .PP Install the given types within the package. This makes the types automatically exportable by adding them to \f(CW@EXPORT_OK\fR of the package. Types are expected to be an array ref where every type is of the following format: .PP .Vb 9 \& { \& name => \*(AqMyType\*(Aq, \& test => sub { check_the_value_somehow($_[0]) }, \& message => sub { "$_[0] is not the type we want!" }, \& subtype_of => \*(AqSomeParentType\*(Aq, # Optional \& from => \*(AqSome::Parent::CoolTypes\*(Aq, # Optional \& parameterizable => sub { ... }, # Optional \& inflate => sub { ... }, # Optional \& } .Ve .PP A type can be declared with a reference (\fIsubtype_of\fR) to some previously declared type. In this case the new type will inherit the behaviour of the referenced type. .PP The referenced type can come either from the same package or from a third party package: .PP .Vb 7 \& MooX::Types::MooseLike::register_types([{ \& name => \*(AqGreaterThan10\*(Aq, \& subtype_of => \*(AqInt\*(Aq, \& from => \*(AqMooX::Types::MooseLike::Base\*(Aq, \& test => sub { $_[0] > 10 }, \& message => sub { \*(Aqnot greater than 10\*(Aq }, \& }], _\|_PACKAGE_\|_); \& \& MooX::Types::MooseLike::register_types([{ \& name => \*(AqBetween10And20\*(Aq, \& subtype_of => \*(AqGreaterThan10\*(Aq, \& from => _\|_PACKAGE_\|_, \& test => sub { $_[0] < 20 }, \& message => sub { \*(Aqnot an integer between 10 and 20\*(Aq }, \& }], _\|_PACKAGE_\|_); \& \& MooX::Types::MooseLike::register_types([{ \& name => \*(AqBetween10And30\*(Aq, \& subtype_of => GreaterThan10(), \& test => sub { $_[0] < 30 }, \& message => sub { \*(Aqnot an integer between 10 and 30\*(Aq }, \& }], _\|_PACKAGE_\|_); .Ve .SS "exception_message" .IX Subsection "exception_message" \&\fBexception_message( value, part_of_the_exception_string )\fR .PP Helper function to be used in a type definition: .PP .Vb 5 \& { \& ... \& message => sub { return exception_message($_[0], \*(Aqa HashRef\*(Aq }, \& ... \& } .Ve .PP In the event of mismatching the type constraints it produces the message: .PP .Vb 1 \& " is not a HashRef!" .Ve .SS "inflate_type" .IX Subsection "inflate_type" \&\fBinflate_type( coderef )\fR .PP Inflates the type to a Moose type. Requires Moose. .SH "SEE ALSO" .IX Header "SEE ALSO" MooX::Types::MooseLike::Numeric \- an example of building subtypes. .PP MooX::Types::SetObject \- an example of building parameterized types. .PP MooX::Types::MooseLike::Email, MooX::Types::MooseLike::DateTime .PP Type::Tiny \- another implementation of type constraints. Compatible with Moo, Moose and Mouse. .SH "AUTHOR" .IX Header "AUTHOR" mateu \- Mateu X. Hunter (cpan:MATEU) .SH "CONTRIBUTORS" .IX Header "CONTRIBUTORS" mst \- Matt S. Trout (cpan:MSTROUT) .PP Mithaldu \- Christian Walde (cpan:MITHALDU) .PP Matt Phillips (cpan:MATTP) .PP Arthur Axel fREW Schmidt (cpan:FREW) .PP Toby Inkster (cpan:TOBYINK) .PP Graham Knop (cpan:HAARG) .PP Dmitry Matrosov (cpan:AMIDOS) .SH "COPYRIGHT" .IX Header "COPYRIGHT" Copyright (c) 2011\-2015 the MooX::Types::MooseLike \*(L"\s-1AUTHOR\*(R"\s0 and \*(L"\s-1CONTRIBUTORS\*(R"\s0 as listed above. .SH "LICENSE" .IX Header "LICENSE" This library is free software and may be distributed under the same terms as perl itself.