The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Form::Tiny::Filter - a representation of a filter

SYNOPSIS

        # in your form class

        # the following will be coerced into Form::Tiny::Filter
        form_filer Str, sub { uc shift() };

DESCRIPTION

This is a simple class which stores a Type::Tiny type and a sub which will perform the filtering.

ATTRIBUTES

type

A Type::Tiny type that will be checked against.

Required.

field

DEPRECATED

A string name of a field that should be filtered, or undef if this filter should execute for every field in the form.

code

A code reference accepting a single scalar and performing the filtering. The scalar will already be checked against the type.

Required.

METHODS

check_field

Accepts a single string, which is a name of a field. Returns a boolean value, which determines whether this filter should be used for that field.

filter

        $filtered = $filter->filter($filtered, @more_params);

Accepts a single scalar, checks if it matches the type and runs the code reference with it as an argument. Can accept more parameters, which will be inserted before the value in the subroutine call (the value is always the last parameter to the coderef).

The return value is the scalar value, either changed or unchanged.