X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMooseX-Types-Structured.git;a=blobdiff_plain;f=lib%2FMooseX%2FTypes%2FStructured.pm;h=ddf09ef80fb5d5dbd6c776acad52b78670a56290;hp=424527cb467664df83cb8f614531fabec0930182;hb=ff801143e71409963bb8b0600118409247c1995b;hpb=c6fece898137da02230305351fdc5e620c355797 diff --git a/lib/MooseX/Types/Structured.pm b/lib/MooseX/Types/Structured.pm index 424527c..ddf09ef 100644 --- a/lib/MooseX/Types/Structured.pm +++ b/lib/MooseX/Types/Structured.pm @@ -572,7 +572,13 @@ Moose::Util::TypeConstraints::get_type_constraint_registry->add_type_constraint( ## Get the constraints and values to check my ($type_constraints, $values) = @_; my @type_constraints = defined $type_constraints ? - @$type_constraints : (); + @$type_constraints : (); + + my $overflow_handler; + if(ref $type_constraints[-1] eq 'CODE') { + $overflow_handler = pop @type_constraints; + } + my @values = defined $values ? @$values: (); ## Perform the checking while(@type_constraints) { @@ -591,8 +597,11 @@ Moose::Util::TypeConstraints::get_type_constraint_registry->add_type_constraint( } ## Make sure there are no leftovers. if(@values) { - warn "I failed since there were left over values"; - return; + if($overflow_handler) { + return $overflow_handler->(@values); + } else { + return; + } } elsif(@type_constraints) { warn "I failed due to left over TC"; return; @@ -610,8 +619,14 @@ Moose::Util::TypeConstraints::get_type_constraint_registry->add_type_constraint( constraint_generator=> sub { ## Get the constraints and values to check my ($type_constraints, $values) = @_; - my %type_constraints = defined $type_constraints ? - @$type_constraints : (); + my @type_constraints = defined $type_constraints ? + @$type_constraints : (); + + my $overflow_handler; + if(ref $type_constraints[-1] eq 'CODE') { + $overflow_handler = pop @type_constraints; + } + my (%type_constraints) = @type_constraints; my %values = defined $values ? %$values: (); ## Perform the checking while(%type_constraints) { @@ -632,7 +647,11 @@ Moose::Util::TypeConstraints::get_type_constraint_registry->add_type_constraint( } ## Make sure there are no leftovers. if(%values) { - return; + if($overflow_handler) { + return $overflow_handler->(%values); + } else { + return; + } } elsif(%type_constraints) { return; } else {