NAME

Valiant::Filter::Each - A Role to create custom validators

SYNOPSIS

package Valiant::Filter::With;

use Moo;

with 'Valiant::Filter::Each';

has cb => (is=>'ro', required=>1);

sub normalize_shortcut {
  my ($class, $arg) = @_;
  if((ref($arg)||'') eq 'CODE') {
    return +{
      cb => $arg,
    };
  }
}

sub filter_each {
  my ($self, $class, $attrs, $attribute_name) = @_;  
  return $self->cb->($class, $attrs, $attribute_name);
}

1;

DESCRIPTION

Use this role when you with to create a custom filter that will be run on your class attributes. Please note that you can also use the 'with' validator (Valiant::Filter::With) for simple custom filter needs. Its best to use this role when you want custom filters that is going to be shared across several classes so the effort pays off in reuse.

Your class must provide the method filter_each, which will be called once for each attribute in the validation.

SEE ALSO

Valiant, Valiant::Filter.

AUTHOR

See Valiant

COPYRIGHT & LICENSE

See Valiant