Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages

  
 
  

home | help
List::Objects::Types(3User Contributed Perl DocumentatiList::Objects::Types(3)

NAME
       List::Objects::Types - Type::Tiny-based types for
       List::Objects::WithUtils

SYNOPSIS
	 package Foo;

	 use List::Objects::Types -all;
	 use List::Objects::WithUtils;
	 use Moo 2;  # version 2+ for better Type::Tiny	support

	 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] }
	 );

DESCRIPTION
       A set of	Type::Tiny-based types & coercions matching the	list objects
       found in	List::Objects::WithUtils.

       ArrayObj

       An object that consumes List::Objects::WithUtils::Role::Array.

       Can be coerced from a plain ARRAY; a shallow copy is performed.

       HashObj

       An object that consumes List::Objects::WithUtils::Role::Hash.

       Can be coerced from a plain HASH; a shallow copy	is performed.

       ImmutableArray

       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.

       TypedArray

       An object that consumes List::Objects::WithUtils::Role::Array::Typed.

       Not coercible.

       TypedArray[`a]

       TypedArray can be parameterized with another type constraint specifying
       the type	of its values.

       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.

       In versions prior to "v2.x", subtypes were permitted; "TypedArray[Num]"
       would accept "array_of(Num, 1, 2, 3.14)"	as expected, but also
       "array_of(Int, 1, 2, 3)"	as "Int" is a subtype "Num". This could	lead
       to unexpected behavior. As of "v2.1.1", this has	been corrected;	the
       latter would be rejected	without	an appropriate coercion	(for example,
       specifying "coerce => 1"	in a Moo(se) attribute along these lines will
       coerce the "Int"-typed array object to "Num")

       (The "examples/"	directory that comes with this distribution contains
       some examples of	parameterized &	coercible TypedArrays.)

       ImmutableTypedArray

       An object that isa List::Objects::WithUtils::Array::Immutable::Typed.

       Not coercible.

       ImmutableTypedArray[`a]

       ImmutableTypedArray can be parameterized	with another type constraint,
       like "TypedArray" (however unlike its mutable counterpart, subtypes are
       accepted).

       Can be coerced from a plain ARRAY or an "ArrayObj".

       TypedHash

       An object that consumes List::Objects::WithUtils::Role::Hash::Typed.

       Not coercible.

       TypedHash[`a]

       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.

       ImmutableTypedHash

       An object that isa List::Objects::WithUtils::Hash::Immutable::Typed.

       Not coercible.

       ImmutableTypedHash[`a]

       ImmutableTypedHash can be parameterized with another type constraint,
       like "TypedHash".

       Can be coerced from a plain HASH	or an "HashObj".

       InflatedHash

       An object that isa List::Objects::WithUtils::Hash::Inflated.

       Can be coerced from a plain HASH	or an "HashObj".

       (Available from v1.2.1)

       InflatedHash[`a]

       InflatedHash can	be parameterized with a	list of	methods	expected to be
       available.

       (Available from v1.3.1)

   SEE ALSO
       MoopsX::ListObjects for integration with	Moops class-building sugar.

       List::Objects::WithUtils	for more on the	relevant list objects.

       Type::Tiny for more on type methods & overloads.

       Types::Standard for a set of useful base	types.

       Type::Library for details on importing types.

AUTHOR
       Jon Portnoy <avenj@cobaltirc.org> with significant contributions	from
       Toby Inkster (CPAN: TOBYINK)

perl v5.32.1			  2016-07-22	       List::Objects::Types(3)

NAME | SYNOPSIS | DESCRIPTION | AUTHOR

Want to link to this manual page? Use this URL:
<https://www.freebsd.org/cgi/man.cgi?query=List::Objects::Types&sektion=3&manpath=FreeBSD+13.0-RELEASE+and+Ports>

home | help