Valiant::Filter::ToArray - Force the value into an arrayref if its not one already
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]
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
This filter defines the following attributes
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.
split
Valiant, Valiant::Filter, Valiant::Validator::Filter.
See Valiant
To install Valiant, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Valiant
CPAN shell
perl -MCPAN -e shell install Valiant
For more information on module installation, please visit the detailed CPAN module installation guide.