line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Exporter::Multi; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
876
|
use Catmandu::Sane; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '1.2020'; |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
12
|
use Catmandu::Util qw(is_string); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
59
|
|
8
|
1
|
|
|
1
|
|
6
|
use Catmandu; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
8
|
|
9
|
1
|
|
|
1
|
|
281
|
use Moo; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
10
|
1
|
|
|
1
|
|
403
|
use namespace::clean; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
7
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
with 'Catmandu::Exporter'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has exporters => ( |
15
|
|
|
|
|
|
|
is => 'ro', |
16
|
|
|
|
|
|
|
default => sub {[]}, |
17
|
|
|
|
|
|
|
coerce => sub { |
18
|
|
|
|
|
|
|
my $exporters = $_[0]; |
19
|
|
|
|
|
|
|
return [ |
20
|
|
|
|
|
|
|
map { |
21
|
|
|
|
|
|
|
if (is_string($_)) { |
22
|
|
|
|
|
|
|
Catmandu->exporter($_); |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
else { |
25
|
|
|
|
|
|
|
$_; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
} @$exporters |
28
|
|
|
|
|
|
|
]; |
29
|
|
|
|
|
|
|
}, |
30
|
|
|
|
|
|
|
); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub add { |
33
|
|
|
|
|
|
|
my ($self, $data) = @_; |
34
|
|
|
|
|
|
|
$_->add($data) for @{$self->exporters}; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub commit { |
38
|
|
|
|
|
|
|
my ($self) = @_; |
39
|
|
|
|
|
|
|
$_->commit for @{$self->exporters}; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|