List::Objects::Types - Type::Tiny-based types for List::Objects::WithUtils
package Foo; use List::Objects::Types -all; use List::Objects::WithUtils; use Moo; use MooX::late; has my_array => ( is => 'ro', isa => ArrayObj, default => sub { array } ); has static_array => ( is => 'ro', isa => ImmutableArray, coerce => 1, default => sub { [qw/ foo bar /] } ); has my_hash => ( is => 'ro', isa => HashObj, coerce => 1, # Coercible from a plain HASH: default => sub { +{} } ); use Types::Standard 'Int', 'Num'; has my_ints => ( is => 'ro', # Nums added to this array_of(Int) are coerced to Ints: isa => TypedArray[ Int->plus_coercions(Num, 'int($_)') ], coerce => 1, default => sub { [1, 2, 3.14] } );
A small set of Type::Tiny-based types & coercions for List::Objects::WithUtils.
Also see MoopsX::ListObjects, which provides Moops class-building sugar with List::Objects::WithUtils integration.
An object that consumes List::Objects::WithUtils::Role::Array.
Can be coerced from a plain ARRAY; a shallow copy is performed.
An object that consumes List::Objects::WithUtils::Role::Hash.
Can be coerced from a plain HASH; a shallow copy is performed.
An object that consumes List::Objects::WithUtils::Role::Array::Immutable.
Can be coerced from a plain ARRAY or an "ArrayObj"; a shallow copy is performed.
An object that consumes List::Objects::WithUtils::Role::Array::Typed.
Not coercible.
TypedArray can be parameterized with another type constraint. For example, the type constraint TypedArray[Num] will accept array_of(Num, 1, 2, 3.14159), and will also accept array_of(Int, 1, 2, 3) because Int is a subtype of Num.
TypedArray[Num]
array_of(Num, 1, 2, 3.14159)
array_of(Int, 1, 2, 3)
Int
Num
Can be coerced from a plain ARRAY or an "ArrayObj"; a shallow copy is performed. If the parameter also has a coercion, this will be applied to each item in the new array.
(The examples/ directory that comes with this distribution contains some examples of parameterized & coercible TypedArrays.)
examples/
An object that isa List::Objects::WithUtils::Array::Immutable::Typed.
ImmutableTypedArray can be parameterized with another type constraint, like "TypedArray".
Can be coerced from a plain ARRAY or an "ArrayObj".
An object that consumes List::Objects::WithUtils::Role::Hash::Typed.
TypedHash can be parameterized with another type constraint, like "TypedArray".
Can be coerced from a plain HASH or a "HashObj". If the parameter also has a coercion, this will be applied to each value in the new hash.
An object that isa List::Objects::WithUtils::Hash::Immutable::Typed.
ImmutableTypedHash can be parameterized with another type constraint, like "TypedHash".
Can be coerced from a plain HASH or an "HashObj".
Jon Portnoy <avenj@cobaltirc.org> with significant contributions from Toby Inkster (CPAN: TOBYINK)
To install List::Objects::Types, copy and paste the appropriate command in to your terminal.
cpanm
cpanm List::Objects::Types
CPAN shell
perl -MCPAN -e shell install List::Objects::Types
For more information on module installation, please visit the detailed CPAN module installation guide.