NAME

Valiant::Filters - Adds a filter DSL and API to your Moo/se classes

SYNOPSIS

package Local::Person;

use Moo;
use Valiant::Filters;

has name => (is => 'ro');
has age => (is => 'ro');

filters name => (
  truncate => { max_length=>25 }
);

filters_with 'Trim';

Filters on specific attributes can be added to the has clause if you prefer:

package Local::Person;

use Moo;
use Valiant::Filters;

has name => (is => 'ro', filters => [ truncate=>25 ] );
has age => (is => 'ro');

filters_with 'Trim';

Using filters on objects:

my $person = Local::Person->new(
    name => ' Ja      ',
    age => 300,
  );

print $person->name; # "Ja" not " Ja      ";

See Valiant for overall overview and Valiant::Filterable for additional API level documentation.

DESCRIPTION

Using this package will apply the Valiant::Filterable role to your current class as well as import several class methods from that role. It also wraps the has imported method so that you can add attribute filters as arguments to has if you find that approach to be neater than calling filter.

You can override several class methods of this package if you need to create your own custom subclass.

IMPORTS

The following subroutines are imported from Valiant::Filterable

filters_with

Accepts the name of a custom filter or a reference to a function, followed by a list of arguments.

filters_with sub {
  my ($class, $attrs, $opts) = @_;
  return $attrs;
};

filters_with 'SpecialFilters', arg1=>'foo', arg2=>'bar';

See filters_with in Valiant::Filterable for more.

filters

Create filters on an object's attributes. Accepts the name of an attribute (or an arrayref of names) followed by a list of filters and global options. Filters can be a subroutine reference or the name of a Filter class.

filters name => sub {
  my ($class, $attrs, $attribute_name) = @_;
  return $attrs->{$attribute_name};  # return the filtered value
};

filters ['name', 'title'] => (
  trim => 1,
);

See filters in Valiant::Filterable for more.

METHODS

The following class methods are available for subclasses

default_roles

Roles that are applied when using this class. Default is Valiant::Filterable. If you are subclassing and wish to apply more roles, or if you've made your own version of Valiant::Filterable you can override this method.

default_exports

Methods that are automatically exported into the calling package.

SEE ALSO

Valiant, Valiant::Filterable

AUTHOR

See Valiant

COPYRIGHT & LICENSE

See Valiant