| App-Hachero documentation | Contained in the App-Hachero distribution. |
App::Hachero::Plugin::Output::CSV - Outputs result to STDOUT as CSV
---
plugins:
- module: Output::CSV
outpus result to STDOUT as CSV
Nobuo Danjou <nobuo.danjou@gmail.com>
| App-Hachero documentation | Contained in the App-Hachero distribution. |
package App::Hachero::Plugin::Output::CSV; use strict; use warnings; use base qw(App::Hachero::Plugin::Base); use Text::CSV_XS; sub output : Hook { my ($self, $context, $args) = @_; my $fh = \*STDOUT; my $csv = Text::CSV_XS->new($self->config->{config}->{csv} || {binary => 1, eol => "\n"}); for my $output (@{$self->config->{config}->{output}}) { my ($key, $fields); if (ref $output eq 'HASH') { ($key, $fields) = %$output; } else { $key = $output; } my $result = $context->result->{$key}; for my $data ($result->values) { my @cols; for my $key ($fields ? @$fields : $data->keys) { push @cols, $data->value($key); } $csv->print($fh, \@cols); } } } 1; __END__