HTML::FormFu::Filter::Split - filter splitting a singe value into an arrayref


HTML-FormFu documentation Contained in the HTML-FormFu distribution.

Index


Code Index:

NAME

Top

HTML::FormFu::Filter::Split - filter splitting a singe value into an arrayref

SYNOPSIS

Top

    type: Split
    regex: '-'

DESCRIPTION

Top

Split a single input value into an arrayref of values.

METHODS

Top

regex

A regex object or string to be passed as the PATTERN argument to split.

Default Value: '' (emtpy string)

limit

A number passed as the LIMIT argument to split.

Default Value: 0

AUTHOR

Top

Carl Franks, cfranks@cpan.org

LICENSE

Top

This library is free software, you can redistribute it and/or modify it under the same terms as Perl itself.


HTML-FormFu documentation Contained in the HTML-FormFu distribution.

package HTML::FormFu::Filter::Split;

use Moose;
extends 'HTML::FormFu::Filter';

has regex => ( is => 'rw', traits => ['Chained'] );
has limit => ( is => 'rw', traits => ['Chained'] );

sub filter {
    my ( $self, $value ) = @_;

    return if !defined $value;

    my $regex = $self->regex;
    my $limit = $self->limit || 0;

    $regex = '' if !defined $regex;

    my @values = split /$regex/, $value, $limit;

    return if !@values;

    return \@values;
}

__PACKAGE__->meta->make_immutable;

1;

__END__