1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
package Catmandu::Validator::Mock;
use Catmandu::Sane;
our $VERSION = '1.2024';
use Moo;
use namespace::clean;
with 'Catmandu::Validator';
has message => (is => 'rw', default => sub {'item is invalid'});
has reject => (is => 'rw', default => sub {0});
sub validate_data {
my ($self) = @_;
if ($self->reject) {
return [$self->message];
}
}
1;
__END__
=pod
=head1 NAME
Catmandu::Validator::Mock - Validate items based on a flag
=head1 SYNOPSIS
use Catmandu::Validator::Mock;
my $validator = Catmandu::Validator::Mock->new(
message => 'item is invalid',
reject => 1,
);
=head1 DESCRIPTION
This L<Catmandu::Validator> can be used for testing as it does not actually
look at the data to validate. Instead it rejects items if C<reject> is set to a
true value.
=head1 CONFIGURATION
=over
=item message
Error message to return for rejected items.
=item reject
The validator marks all items as invalid as long as this flag is true. Default
is false.
=back
=head1 SEE ALSO
See L<Catmandu::Validator> for inherited methods, common configuration options,
and usage.
=cut
|