The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

MooseX::TypeMap - A type-constraint-to-data map

SYNOPSIS

    use MooseX::Types::Moose qw(Str Int Num Value);

    my $map = MooseX::TypeMap->new(
      type_entries => [
        MooseX::TypeMap::Entry->new(
          data => 'number',
          type_constraint => Num,
        )
      ],
      subtype_entries => [
        MooseX::TypeMap::Entry->new(
          data => 'string',
          type_constraint => Str,
        )
      ]
    );

    $map->resolve(Int); #returns 'string'
    $map->resolve(Num); #returns 'number'
    $map->resolve(Str); #returns 'string'
    $map->resolve(Value); #returns an undefined value

ATTRIBUTES

type_entries

type_entries - dereferencing reader
_build_entries - builder, defaults to []

An ArrayRef of Entry objects. These entry objects will only match on "resolve" when the type constraint given is equal to the type constraint in the entry.

subtype_entries

subtype_entries - dereferencing reader
_build_subtype_entries - builder, defaults to []

An ArrayRef of Entry objects. These entry objects will match on "resolve" when the type constraint given is equal to, or a sub-type of, the type constraint in the entry.

_sorted_entries

_sorted_entries - dereferencing reader
_build__sorted_entries - builder

A private attribute that mantains a sorted array of arrays of entries in the order in which they will be looked at if there is no matching entry in entries This attribute can not be set from the constructor, has no public methods and is only being documented for the benefit of future contributors.

METHODS

new

arguments: \%arguments
return value: $object_instance

Constructor. Accepts the following keys: type_entries, subtype_entries.

clone_with_additional_types

arguments: \%arguments
return value: $object_instance

Clone the current typemap with additional type_entries and subtype_entries and return the new instance which includes all the current entries and the additional ones provided. If \%arguments is ommitted, type map returned will be an identical clone of the invocant.

find_matching_entry

arguments: $type

Will return the $entry $type resolves to, or an undefined value if no matching entry is found.

has_entry_for

arguments: $type

Will return true if the given $type resolves to an entry and false otherwise.

resolve

arguments: $type

Will find the closest matching entry for $type and return the contents of the entry's data attribute;

AUTHORS

Yuval Kogman <nothingmuch@woobling.org>
Florian Ragwitz <rafl@debian.org>
Guillermo Roditi <groditi@cpan.org>

AUTHORS, COPYRIGHT AND LICENSE

This software is copyright (c) 2008, 2009, 2010 by its authos as listed in the "AUTHORS" section.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

3 POD Errors

The following errors were encountered while parsing the POD:

Around line 281:

Unknown directive: =items

Around line 294:

Unknown directive: =items

Around line 306:

Unknown directive: =items