## 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) {
}
## 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;
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) {
}
## Make sure there are no leftovers.
if(%values) {
- return;
+ if($overflow_handler) {
+ return $overflow_handler->(%values);
+ } else {
+ return;
+ }
} elsif(%type_constraints) {
return;
} else {