isa=>'Object',
predicate=>'has_dependent_type_constraint',
handles=>{
- check_dependent=>'check',
+ check_dependent=>'check',
+ get_message_dependent=>'get_message',
},
);
return $self;
};
+=head2 validate
+
+We intercept validate in order to custom process the message
+
+
+=cut
+
+around 'check' => sub {
+ my ($check, $self, @args) = @_;
+ my ($result, $message) = $self->_compiled_type_constraint->(@args);
+ warn $result;
+ return $result;
+};
+
+around 'validate' => sub {
+ my ($validate, $self, @args) = @_;
+ my ($result, $message) = $self->_compiled_type_constraint->(@args);
+
+ if($result) {
+ return $result;
+ } else {
+ if(defined $message) {
+ return "Inner: $message";
+ } else { warn '......................';
+ return $self->get_message(@args);
+ }
+ }
+};
+
=head2 generate_constraint_for ($type_constraints)
Given some type constraints, use them to generate validation rules for an ref
sub generate_constraint_for {
my ($self, $callback) = @_;
return sub {
- my ($dependent_pair) = @_;
+ my $dependent_pair = shift @_;
my ($dependent, $constraining) = @$dependent_pair;
## First need to test the bits
unless($self->check_dependent($dependent)) {
- return;
+ return (undef, 'bbbbbb');
}
unless($self->check_constraining($constraining)) {
ok !UniqueInt2->check([10,[1,10,15]]), 'not unique in set';
ok !UniqueInt2->check([2,[3..6]]), 'FAIL dependent is too small';
ok UniqueInt2->check([3,[100..110]]), 'PASS unique in set';
- ok UniqueInt2->check([4,[100..110]]), 'PASS unique in set';
+ ok UniqueInt2->check([4,[100..110]]), 'PASS unique in set';
+
+ ## Basic error messages. TODO should be it's own test
+
+ warn UniqueInt2->validate(['a',[1,2,3]]);
}