| 1 | package Catmandu::Exporter::Multi; | ||||||||||
| 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 Catmandu::Util qw(is_string); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 1 | ▶ | use Catmandu; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 1 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 1 | ▶ | use namespace::clean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 1 | with 'Catmandu::Exporter'; | |||||||||
| 13 | |||||||||||
| 14 | has exporters => ( | ||||||||||
| 15 | is => 'ro', | ||||||||||
| 16 | 0 | ▶ | default => sub {[]}, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 17 | coerce => sub { | ||||||||||
| 18 | 1 | ▶ | my $exporters = $_[0]; | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.4
| |||||||||||
| 19 | return [ | ||||||||||
| 20 | map { | ||||||||||
| 21 | 1 | ▶ | if (is_string($_)) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 22 | 0 | Catmandu->exporter($_); | |||||||||
| 23 | } | ||||||||||
| 24 | else { | ||||||||||
| 25 | 2 | $_; | |||||||||
| 26 | } | ||||||||||
| 27 | } @$exporters | ||||||||||
| 28 | ]; | ||||||||||
| 29 | }, | ||||||||||
| 30 | 1 | ); | |||||||||
| 31 | |||||||||||
| 32 | sub add { | ||||||||||
| 33 | 3 | ▶ | my ($self, $data) = @_; | ||||||||
|
Subroutine
add: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 34 | 3 | $_->add($data) for @{$self->exporters}; | |||||||||
| 35 | } | ||||||||||
| 36 | |||||||||||
| 37 | sub commit { | ||||||||||
| 38 | 1 | ▶ | my ($self) = @_; | ||||||||
|
Subroutine
commit: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 39 | 1 | $_->commit for @{$self->exporters}; | |||||||||
| 40 | } | ||||||||||
| 41 | |||||||||||
| 42 | 1 | 1; | |||||||||
| 43 | |||||||||||
| 44 | __END__ | ||||||||||
| 45 | |||||||||||
| 46 | =pod | ||||||||||
| 47 | |||||||||||
| 48 | =head1 NAME | ||||||||||
| 49 | |||||||||||
| 50 | Catmandu::Exporter::Multi - export you data to multiple exporters | ||||||||||
| 51 | |||||||||||
| 52 | =head1 SYNOPSIS | ||||||||||
| 53 | |||||||||||
| 54 | # this will write both a CSV and an XLS file | ||||||||||
| 55 | my $exporter = Catmandu::Exporter::Multi->new(exporters => [ | ||||||||||
| 56 | Catmandu::Exporter::CSV->new(file => 'mydata.csv'), | ||||||||||
| 57 | Catmandu::Exporter::XLS->new(file => 'mydata.xls'), | ||||||||||
| 58 | ]); | ||||||||||
| 59 | $exporter->add({col1 => 'val1', col2 => 'val2'}); | ||||||||||
| 60 | $exporter->commit; | ||||||||||
| 61 | |||||||||||
| 62 | =head1 SEE ALSO | ||||||||||
| 63 | |||||||||||
| 64 | L<Catmandu::Exporter> | ||||||||||
| 65 | |||||||||||
| 66 | =cut | ||||||||||
| 67 | |||||||||||