| 1 | package Catmandu::Fix::join_field; | ||
| 2 | |||
| 3 | 1 | ▶ | use Catmandu::Sane; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | |||
| 5 | 1 | our $VERSION = '1.0201_02'; | |
| 6 | |||
| 7 | 1 | ▶ | use Moo; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | 1 | ▶ | use namespace::clean; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | 1 | ▶ | use Catmandu::Fix::Has; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 10 | |||
| 11 | 1 | has path => (fix_arg => 1); | |
| 12 | 0 | ▶ | has join_char => (fix_arg => 1, default => sub {''}); |
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||
| 13 | |||
| 14 | 1 | with 'Catmandu::Fix::SimpleGetValue'; | |
| 15 | |||
| 16 | sub emit_value { | ||
| 17 | 5 | ▶ | my ($self, $var, $fixer) = @_; |
|
Subroutine
emit_value: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 18 | 5 | my $join_char = $fixer->emit_string($self->join_char); | |
| 19 | |||
| 20 | 5 | "if (is_array_ref(${var})) {" | |
| 21 | . "${var} = join(${join_char}, grep { is_value(\$_) } \@{${var}});" | ||
| 22 | . "}"; | ||
| 23 | } | ||
| 24 | |||
| 25 | 1 | 1; | |
| 26 | |||
| 27 | __END__ | ||
| 28 | |||
| 29 | =pod | ||
| 30 | |||
| 31 | =head1 NAME | ||
| 32 | |||
| 33 | Catmandu::Fix::join_field - join the ARRAY values of a field into a string | ||
| 34 | |||
| 35 | =head1 SYNOPSIS | ||
| 36 | |||
| 37 | # Join the array values of a field into a string. E.g. foo => [1,2,3] | ||
| 38 | join_field(foo, /) # foo => "1/2/3" | ||
| 39 | |||
| 40 | =head1 SEE ALSO | ||
| 41 | |||
| 42 | L<Catmandu::Fix> | ||
| 43 | |||
| 44 | =cut | ||