Path::Router::Types - A set of types that Path::Router uses


Path-Router documentation Contained in the Path-Router distribution.

Index


Code Index:

NAME

Top

Path::Router::Types - A set of types that Path::Router uses

SYNOPSIS

Top

  use Path::Router::Types;

DESCRIPTION

Top

BUGS

Top

All complex software has bugs lurking in it, and this module is no exception. If you find a bug please either email me, or add the bug to cpan-RT.

AUTHOR

Top

Stevan Little <stevan.little@iinteractive.com>

COPYRIGHT AND LICENSE

Top


Path-Router documentation Contained in the Path-Router distribution.

package Path::Router::Types;
use Moose ();
use Moose::Util::TypeConstraints;

our $VERSION   = '0.10';
our $AUTHORITY = 'cpan:STEVAN';

class_type 'Moose::Meta::TypeConstraint';

subtype 'Path::Router::Route::ValidationMap'
    => as 'HashRef[Moose::Meta::TypeConstraint]';
    
# NOTE:
# canonicalize the route 
# validators into a simple
# set of type constraints
# - SL
coerce 'Path::Router::Route::ValidationMap'
    => from 'HashRef[Str | RegexpRef | Moose::Meta::TypeConstraint]'
        => via {
            my %orig = %{ +shift };
            foreach my $key (keys %orig) {
                my $val = $orig{$key};
                if (ref $val eq 'Regexp') {
                    $orig{$key} = subtype('Str' => where{ /^$val$/ });
                }
                else {
                    $orig{$key} = find_type_constraint($val) 
                        || Carp::confess "Could not locate type constraint named $val"; 
                }
            }            
            return \%orig;
        };

no Moose; no Moose::Util::TypeConstraints; 1;

__END__