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
|
package Catmandu::Exporter::Multi;
use Catmandu::Sane;
our $VERSION = '1.2024';
use Catmandu::Util qw(is_string);
use Catmandu;
use Moo;
use namespace::clean;
with 'Catmandu::Exporter';
has exporters => (
is => 'ro',
default => sub {[]},
coerce => sub {
my $exporters = $_[0];
return [
map {
if (is_string($_)) {
Catmandu->exporter($_);
}
else {
$_;
}
} @$exporters
];
},
);
sub add {
my ($self, $data) = @_;
$_->add($data) for @{$self->exporters};
}
sub commit {
my ($self) = @_;
$_->commit for @{$self->exporters};
}
1;
__END__
=pod
=head1 NAME
Catmandu::Exporter::Multi - export you data to multiple exporters
=head1 SYNOPSIS
# this will write both a CSV and an XLS file
my $exporter = Catmandu::Exporter::Multi->new(exporters => [
Catmandu::Exporter::CSV->new(file => 'mydata.csv'),
Catmandu::Exporter::XLS->new(file => 'mydata.xls'),
]);
$exporter->add({col1 => 'val1', col2 => 'val2'});
$exporter->commit;
=head1 SEE ALSO
L<Catmandu::Exporter>
=cut
|