Valiant::Filter::Flatten - Array or Hash ref to string
package Local::Test; use Moo; use Valiant::Filters; has 'pick_first' => (is=>'ro', required=>1); has 'pick_last' => (is=>'ro', required=>1); has 'join' => (is=>'ro', required=>1); has 'sprintf' => (is=>'ro', required=>1); has 'pattern' => (is=>'ro', required=>1); filters pick_first => (flatten => +{pick => 'first'}); filters pick_last => (flatten => +{pick => 'last'}); filters join => (flatten => +{join => ','}); filters sprintf => (flatten => +{sprintf => '%s-%s-%s'}); filters pattern => (flatten => +{pattern => 'hi {{a}} there {{b}}'}); my $object = Local::Test->new( pick_first => [1,2,3], pick_last => [1,2,3], join => [1,2,3], sprintf => [1,2,3], pattern => +{ a=>'now', b=>'john' }, ); print $object->pick_first; # 1 print $object->pick_last; # 3 print $object->join; # '1,2,3' print $object->sprintf; # '1-2-3' print $object->pattern; # 'hi now there john'
Given an arrayref for a value, flatten to a string in various ways
This filter defines the following attributes
Value of either 'first' or 'last' which indicates choosing either the first or last index of the arrayref.
Join the arrayref into a string using the value of 'join' as the deliminator
Use sprintf formatted string to convert an arrayref.
sprintf
Uses a Valiant style pattern string to convert a hashref to a string. Basically inside the pattern string we look for "{{$key}}" and substitute $key for whatever matches in the incoming hashref as a key value. If there's no match we replace with an empty string without raising warnings.
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.