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

NAME

Valiant::Filter::Flatten - Array or Hash ref to string

SYNOPSIS

    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'

DESCRIPTION

Given an arrayref for a value, flatten to a string in various ways

ATTRIBUTES

This filter defines the following attributes

pick

Value of either 'first' or 'last' which indicates choosing either the first or last index of the arrayref.

join

Join the arrayref into a string using the value of 'join' as the deliminator

sprintf

Use sprintf formatted string to convert an arrayref.

pattern

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.

SEE ALSO

Valiant, Valiant::Filter, Valiant::Validator::Filter.

AUTHOR

See Valiant

COPYRIGHT & LICENSE

See Valiant