1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
package Catmandu::Fix::export_to_string;
use Catmandu::Sane;
our $VERSION = '1.2024';
use Moo;
use Catmandu::Util::Path qw(as_path);
use Catmandu;
use namespace::clean;
use Catmandu::Fix::Has;
with 'Catmandu::Fix::Builder';
has path => (fix_arg => 1);
has name => (fix_arg => 1);
has opts => (fix_opt => 'collect');
sub _build_fixer {
my ($self) = @_;
my $name = $self->name;
my $opts = $self->opts;
as_path($self->path)->updater(
if => [
[qw(array_ref hash_ref)] =>
sub {Catmandu->export_to_string($_[0], $name, %$opts)}
]
);
}
1;
__END__
=pod
=head1 NAME
Catmandu::Fix::export_to_string - convert the value of field using a named exporter
=head1 SYNOPSIS
export_to_string(my.field,'YAML')
export_to_string(my.field2,'JSON')
export_to_string(my.field3,'CSV', 'sep_char' => ';' )
=head1 DESCRIPTION
=head2 export_string( PATH, NAME [, EXPORT_OPTIONS ] )
This fix uses the function export_to_string of the package L<Catmandu>, but requires the NAME of the exporter.
It expects a HASH or ARRAY as input. Other values are silently ignored.
=over 4
=item PATH
=item NAME
name of the exporter to use. As usual in Catmandu, one can choose:
* full package name of the exporter (e.g. 'Catmandu::Exporter::JSON')
* short package name of the exporter (e.g. 'JSON')
* name of the exporter as declared in the Catmandu configuration
=item EXPORT_OPTIONS
extra options for the named exporter
=back
=head1 AUTHOR
Nicolas Franck, C<< <nicolas.franck at ugent.be> >>
=head1 SEE ALSO
L<Catmandu::Fix>
=cut
|