![]() |
![]()
| ![]() |
![]()
NAMEType::Tiny::Union - union type constraints SYNOPSISUsing via the "|" operator overload: package Local::Stash { use Moo; use Types::Common qw( ArrayRef HashRef ); has data => ( is => 'ro', isa => HashRef | ArrayRef, ); } my $x = Local::Stash->new( data => {} ); # ok my $y = Local::Stash->new( data => [] ); # ok Using Type::Tiny::Union's object-oriented interface: package Local::Stash { use Moo; use Types::Common qw( ArrayRef HashRef ); use Type::Tiny::Union; my $AnyData = Type::Tiny::Union->new( name => 'AnyData', type_constraints => [ HashRef, ArrayRef ], ); has data => ( is => 'ro', isa => $AnyData, ); } Using Type::Utils's functional interface: package Local::Stash { use Moo; use Types::Common qw( ArrayRef HashRef ); use Type::Utils; my $AnyData = union AnyData => [ HashRef, ArrayRef ]; has data => ( is => 'ro', isa => $AnyData, ); } STATUSThis module is covered by the Type-Tiny stability policy. DESCRIPTIONUnion type constraints. This package inherits from Type::Tiny; see that for most documentation. Major differences are listed below: ConstructorThe "new" constructor from Type::Tiny still works, of course. But there is also:
Attributes
Methods
Overloading
BUGSPlease report any bugs to <https://github.com/tobyink/p5-type-tiny/issues>. SEE ALSOType::Tiny::Manual. Type::Tiny. 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.
|