|
NAMEType::Tiny::Class - type constraints based on the "isa" method SYNOPSISUsing via Types::Standard: package Local::Horse {
use Moo;
use Types::Standard qw( Str InstanceOf );
has name => (
is => 'ro',
isa => Str,
);
has owner => (
is => 'ro',
isa => InstanceOf[ 'Local::Person' ],
default => sub { Local::Person->new },
);
}
Using Type::Tiny::Class's export feature: package Local::Horse {
use Moo;
use Types::Standard qw( Str );
use Type::Tiny::Class 'Local::Person';
has name => (
is => 'ro',
isa => Str,
);
has owner => (
is => 'ro',
isa => LocalPerson,
default => sub { LocalPerson->new },
);
}
Using Type::Tiny::Class's object-oriented interface: package Local::Horse {
use Moo;
use Types::Standard qw( Str );
use Type::Tiny::Class;
my $Person = Type::Tiny::Class->new( class => 'Local::Person' );
has name => (
is => 'ro',
isa => Str,
);
has owner => (
is => 'ro',
isa => $Person,
default => sub { $Person->new },
);
}
Using Type::Utils's functional interface: package Local::Horse {
use Moo;
use Types::Standard qw( Str );
use Type::Utils;
my $Person = class_type 'Local::Person';
has name => (
is => 'ro',
isa => Str,
);
has owner => (
is => 'ro',
isa => $Person,
default => sub { $Person->new },
);
}
STATUSThis module is covered by the Type-Tiny stability policy. DESCRIPTIONType constraints of the general form "{ $_->isa("Some::Class") }". This package inherits from Type::Tiny; see that for most documentation. Major differences are listed below: Constructor
Attributes
Methods
ExportsType::Tiny::Class can be used as an exporter. use Type::Tiny::Class 'HTTP::Tiny'; This will export the following functions into your namespace: You will also be able to use "HTTPTiny->new(...)" as a shortcut for "HTTP::Tiny->new(...)". Multiple types can be exported at once: use Type::Tiny::Class qw( HTTP::Tiny LWP::UserAgent ); BUGSPlease report any bugs to <https://github.com/tobyink/p5-type-tiny/issues>. SEE ALSOType::Tiny::Manual. Type::Tiny. Moose::Meta::TypeConstraint::Class. AUTHORToby Inkster <tobyink@cpan.org>. COPYRIGHT AND LICENCEThis software is copyright (c) 2013-2014, 2017-2025 by Toby Inkster. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. DISCLAIMER OF WARRANTIESTHIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|