What is Type::Tiny?
Type::Tiny is a small Perl class for writing type constraints, inspired by Moose's type constraint API and MooseX::Types. It has only one non-core dependency (and even that is simply a module that was previously distributed as part of Type::Tiny but has since been spun off), and can be used with Moose , Mouse , or Moo (or none of the above).
Type::Tiny is used by over 1000 Perl distributions on the CPAN (Comprehensive Perl Archive Network) and can be considered a stable and mature framework for efficiently and reliably enforcing data types.
Get Type-Tiny
Get Type-Tiny v2.6.0 from CPAN.
Earlier versions of Type-Tiny are available on the CPAN , but a lot of effort is kept to maintain backwards compatibility with Type-Tiny 1.000000, so installing an older version should almost never be necessary.
What people are saying
A quick example
use v5.12;
use strict;
use warnings;
package Horse {
use Moo;
use Types::Standard qw( Str Int Enum ArrayRef InstanceOf );
use Type::Params qw( signature );
use namespace::autoclean;
has name => (
is => 'ro',
isa => Str,
required => 1,
);
has gender => (
is => 'ro',
isa => Enum[qw( f m )],
);
has age => (
is => 'rw',
isa => Int->where( '$_ >= 0' ),
);
has children => (
is => 'ro',
isa => ArrayRef[ InstanceOf['Horse'] ],
default => sub { return [] },
);
sub add_child {
state $check = signature(
method => Object,
positional => [ InstanceOf['Horse'] ]
);
my ( $self, $child ) = $check->(@_); # unpack @_
push @{ $self->children }, $child;
return $self;
}
}
Features
- Type check values in constructors and attribute setters in object-oriented programming.
- Check the types of function/method parameters.
- Tie a type constraint to a variable.
- Check the type of values on-the-fly.
- Fast type constraint checks, with an optional implementation in C.
Download
Distributions
If you are using Linux, BSD, or a similar operating system, and you are using the system copy of Perl (usually
/usr/bin/perl
), then the best way to install Type-Tiny is using your operating system's package management tools.
Type-Tiny is available for most Linux and BSD distributions.
Arch Linux | perl-type-tiny |
---|---|
Debian | libtype-tiny-perl |
Fedora OS | perl-Type-Tiny |
Manjaro | perl-type-tiny |
Redhat | perl-Type-Tiny |
SuSE | perl-Type-Tiny |
Ubuntu | libtype-tiny-perl |
FreeBSD | p5-Type-Tiny |
CPAN
If you are using a non-system copy of Perl (for example, one installed in your home directory, or via perlbrew), then you should install Type-Tiny from CPAN.
Further installation advice is available.
Github
Rarely, you will want to install the latest version from Github .
Extras
Some of the features discussed on this website are not included in the main Type-Tiny distribution, but in external distributions. In particular, Exporter-Tiny , Type-API , Types-Self , and Types-Path-Tiny .
Powered by Perl
What is Perl?
Perl is a high-level, general-purpose, interpreted, dynamic programming language. Perl was developed by Larry Wall in 1987 as a general-purpose Unix scripting language to make report processing easier. Since then, it has undergone many changes and revisions. In 1998, it was also referred to as the "duct tape that holds the Internet together."