| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
use Catmandu::Sane; |
|
3
|
7
|
|
|
7
|
|
3410
|
|
|
|
7
|
|
|
|
|
16
|
|
|
|
7
|
|
|
|
|
45
|
|
|
4
|
|
|
|
|
|
|
our $VERSION = '1.2019'; |
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use Catmandu::Util qw(:is :check); |
|
7
|
7
|
|
|
7
|
|
50
|
use Moo::Role; |
|
|
7
|
|
|
|
|
15
|
|
|
|
7
|
|
|
|
|
3018
|
|
|
8
|
7
|
|
|
7
|
|
52
|
|
|
|
7
|
|
|
|
|
14
|
|
|
|
7
|
|
|
|
|
50
|
|
|
9
|
|
|
|
|
|
|
my $fields = $_[0]; |
|
10
|
|
|
|
|
|
|
if (ref $fields eq 'ARRAY') {return $fields} |
|
11
|
|
|
|
|
|
|
if (ref $fields eq 'HASH') {return [sort keys %$fields]} |
|
12
|
|
|
|
|
|
|
[split ',', $fields]; |
|
13
|
|
|
|
|
|
|
} |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
use namespace::clean; |
|
16
|
|
|
|
|
|
|
|
|
17
|
7
|
|
|
7
|
|
4209
|
with 'Catmandu::Exporter'; |
|
|
7
|
|
|
|
|
18
|
|
|
|
7
|
|
|
|
|
37
|
|
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
has fields => (is => 'rwp', coerce => \&_coerce_array,); |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
has columns => (is => 'rwp', coerce => \&_coerce_array,); |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
has collect_fields => (is => 'ro',); |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
has header => (is => 'ro', default => sub {1}); |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
around add => sub { |
|
28
|
|
|
|
|
|
|
my ($orig, $self, $data) = @_; |
|
29
|
|
|
|
|
|
|
$self->_set_fields($data) unless $self->fields; |
|
30
|
|
|
|
|
|
|
$orig->($self, $data); |
|
31
|
|
|
|
|
|
|
}; |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
around add_many => sub { |
|
34
|
|
|
|
|
|
|
my ($orig, $self, $many) = @_; |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
if ($self->collect_fields && !$self->fields) { |
|
37
|
|
|
|
|
|
|
my $coll; |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
if (is_array_ref($many)) { |
|
40
|
|
|
|
|
|
|
$coll = $many; |
|
41
|
|
|
|
|
|
|
} |
|
42
|
|
|
|
|
|
|
elsif (is_hash_ref($many)) { |
|
43
|
|
|
|
|
|
|
$coll = [$many]; |
|
44
|
|
|
|
|
|
|
} |
|
45
|
|
|
|
|
|
|
else { |
|
46
|
|
|
|
|
|
|
if (is_invocant($many)) { |
|
47
|
|
|
|
|
|
|
$many = check_able($many, 'generator')->generator; |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
check_code_ref($many); |
|
50
|
|
|
|
|
|
|
$coll = []; |
|
51
|
|
|
|
|
|
|
while (defined(my $data = $many->())) { |
|
52
|
|
|
|
|
|
|
push @$coll, $data; |
|
53
|
|
|
|
|
|
|
} |
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
my $keys = {}; |
|
57
|
|
|
|
|
|
|
for my $data (@$coll) { |
|
58
|
|
|
|
|
|
|
for my $key (keys %$data) { |
|
59
|
|
|
|
|
|
|
$keys->{$key} ||= 1; |
|
60
|
|
|
|
|
|
|
} |
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
$self->_set_fields($keys); |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
$many = $coll; |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
$orig->($self, $many); |
|
68
|
|
|
|
|
|
|
}; |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
1; |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=pod |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 NAME |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
Catmandu::TabularExporter - base role for tabular exporters like CSV |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
See L<Catmandu::Exporter> for the base functionality of this role. This role |
|
82
|
|
|
|
|
|
|
adds some functionality tailored to tabular or columnar exporters. |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head1 CONFIGURATION |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=over |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=item fields |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
The fields to be mapped. Can be an arrayref, example hashref or comma |
|
91
|
|
|
|
|
|
|
separated string. If missing, the fields of the first record encountered will |
|
92
|
|
|
|
|
|
|
be used. If C<collect_fields> is true, all fields names in the record stream |
|
93
|
|
|
|
|
|
|
will be collected first. |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=item columns |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Optional custom column labels. Can be an arrayref, example hashref or comma |
|
98
|
|
|
|
|
|
|
separated string. |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=item collect_fields |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
See C<fields> for a description. Note that this option will cause all records |
|
103
|
|
|
|
|
|
|
in the stream to be buffered in memory. |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=item header |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
Include a header with column names. Enabled by default. |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=back |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=cut |
|
112
|
|
|
|
|
|
|
|