line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
use Catmandu::Sane; |
3
|
3
|
|
|
3
|
|
776
|
|
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
24
|
|
4
|
|
|
|
|
|
|
our $VERSION = '1.2019'; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use Moo; |
7
|
3
|
|
|
3
|
|
20
|
use Catmandu::Util::Path qw(as_path); |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
20
|
|
8
|
3
|
|
|
3
|
|
1824
|
use namespace::clean; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
161
|
|
9
|
3
|
|
|
3
|
|
19
|
use Catmandu::Fix::Has; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
16
|
|
10
|
3
|
|
|
3
|
|
1197
|
|
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
22
|
|
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
|
|
|
|
|
12
|
); |
|
3
|
|
|
|
|
32
|
|
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
my ($self) = @_; |
27
|
|
|
|
|
|
|
my $exporter = $self->exporter; |
28
|
|
|
|
|
|
|
my $getter = as_path($self->path)->getter; |
29
|
3
|
|
|
3
|
|
32
|
sub { |
30
|
3
|
|
|
|
|
170
|
my $data = $_[0]; |
31
|
3
|
|
|
|
|
29
|
my $vals = $getter->($data); |
32
|
|
|
|
|
|
|
$exporter->add($_) for @$vals; |
33
|
3
|
|
|
3
|
|
7
|
$data; |
34
|
3
|
|
|
|
|
56
|
}; |
35
|
3
|
|
|
|
|
66
|
} |
36
|
3
|
|
|
|
|
64
|
|
37
|
3
|
|
|
|
|
55
|
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 |