NAME

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

SYNOPSIS

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

my $map = MooseX::TypeMap->new(
  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

entries

A read-only 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.

The following methods are associated with this attribute:

entries - reader
_build_entries - builder, defaults to []

subtype_entries

A read-only 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.

The following methods are associated with this attribute:

subtype_entries - reader
_build_subtype_entries - builder, defaults to []

_sorted_entries

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.

The following methods are associated with this attribute:

_sorted_entries - reader
_build__sorted_entries - builder

METHODS

new

arguments: \%arguments
return value: $object_instance

Constructor. Accepts the following keys: entries, subtype_entries.

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 entries 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 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 206:

Unknown directive: =items

Around line 219:

Unknown directive: =items

Around line 231:

Unknown directive: =items