NAME
Valiant::Filter::ToArray - Force the value into an arrayref if its not one already
SYNOPSIS
package Local::Test;
use Moo;
use Valiant::Filters;
has 'string' => (is=>'ro', required=>1);
has 'array' => (is=>'ro', required=>1);
has 'split' => (is=>'ro', required=>1);
filters ['string', 'array'] => (to_array => 1);
filters split => (to_array => +{ split_on => ',' } );
my $object = Local::Test->new(
string => 'foo',
array => ['bar', 'baz'],
split = '123',
);
$object->string; # ['foo']
$object->array; # ['bar', 'baz']
$object->split: # [1, 2, 3]
DESCRIPTION
Force any scalar values to arrayref. Basically normalize on an arrayref. Allows you to specific a split pattern or just make the string into an arrayref
ATTRIBUTES
This filter defines the following attributes
split_on
Optional. A pattern used via split
to split a string into an arrayref. If not present just use the string as is to make an arrayref.
SEE ALSO
Valiant, Valiant::Filter, Valiant::Validator::Filter.
AUTHOR
See Valiant
COPYRIGHT & LICENSE
See Valiant