line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
use Catmandu::Sane; |
3
|
3
|
|
|
3
|
|
952
|
|
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
23
|
|
4
|
|
|
|
|
|
|
our $VERSION = '1.2018'; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use Moo; |
7
|
3
|
|
|
3
|
|
20
|
use Catmandu::Util::Path qw(as_path); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
17
|
|
8
|
3
|
|
|
3
|
|
1777
|
use namespace::clean; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
157
|
|
9
|
3
|
|
|
3
|
|
19
|
use Catmandu::Fix::Has; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
29
|
|
10
|
3
|
|
|
3
|
|
1167
|
|
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
21
|
|
11
|
|
|
|
|
|
|
has path => (fix_arg => 1); |
12
|
|
|
|
|
|
|
has exporter_name => (fix_arg => 1); |
13
|
|
|
|
|
|
|
has exporter_args => (fix_opt => 'collect'); |
14
|
|
|
|
|
|
|
has exporter => (is => 'lazy', init_arg => undef); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
with 'Catmandu::Fix::Builder'; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
my ($self) = @_; |
19
|
|
|
|
|
|
|
Catmandu->exporter( |
20
|
3
|
|
|
3
|
|
30
|
$self->exporter_name, |
21
|
|
|
|
|
|
|
%{$self->exporter_args}, |
22
|
|
|
|
|
|
|
autocommit => 1 |
23
|
3
|
|
|
|
|
9
|
); |
|
3
|
|
|
|
|
41
|
|
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
my ($self) = @_; |
27
|
|
|
|
|
|
|
my $exporter = $self->exporter; |
28
|
|
|
|
|
|
|
my $getter = as_path($self->path)->getter; |
29
|
3
|
|
|
3
|
|
30
|
sub { |
30
|
3
|
|
|
|
|
128
|
my $data = $_[0]; |
31
|
3
|
|
|
|
|
24
|
my $vals = $getter->($data); |
32
|
|
|
|
|
|
|
$exporter->add($_) for @$vals; |
33
|
3
|
|
|
3
|
|
7
|
$data; |
34
|
3
|
|
|
|
|
46
|
}; |
35
|
3
|
|
|
|
|
61
|
} |
36
|
3
|
|
|
|
|
87
|
|
37
|
3
|
|
|
|
|
46
|
1; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=pod |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head1 NAME |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
Catmandu::Fix::add_to_exporter - Export a record as side effect |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head1 SYNOPSIS |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# Export the data field values to a CSV file |
49
|
|
|
|
|
|
|
add_to_exporter(data,CSV, file:/tmp/test.txt, header: 1) |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# Export the complete record into a JSON file |
52
|
|
|
|
|
|
|
add_to_exporter(data,JSON, file:/tmp/test.json, pretty:1) |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# In general, export a PATH to an EXPORTER with one ore more OPT0s |
55
|
|
|
|
|
|
|
add_to_exporter(PATH,EXPORTER, OPT1:... , OPT2:... , OPT3:... , ...) |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
# Use the add_to_exporter to explode an ARRAY into many records |
58
|
|
|
|
|
|
|
# E.g. |
59
|
|
|
|
|
|
|
# books: |
60
|
|
|
|
|
|
|
# - title: Graphic Design Rules |
61
|
|
|
|
|
|
|
# year: 2003 |
62
|
|
|
|
|
|
|
# - title: Urban Sketching |
63
|
|
|
|
|
|
|
# year: 2013 |
64
|
|
|
|
|
|
|
# - title: Findus flyttar ut |
65
|
|
|
|
|
|
|
# year: 2012 |
66
|
|
|
|
|
|
|
# And a fix file: exporter.fix |
67
|
|
|
|
|
|
|
do with(path => books) |
68
|
|
|
|
|
|
|
add_to_exporter(.,JSON) |
69
|
|
|
|
|
|
|
end |
70
|
|
|
|
|
|
|
# You can get an output with 3 records using the command line function |
71
|
|
|
|
|
|
|
catmandu convert JSON to Null --fix exporter.fix < book.json |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 SEE ALSO |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
L<Catmandu::Fix> , L<Catmandu::Exporter> |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=cut |