line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Exporter::YAML; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
109466
|
use Catmandu::Sane; |
|
4
|
|
|
|
|
13
|
|
|
4
|
|
|
|
|
33
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '1.2020'; |
6
|
|
|
|
|
|
|
|
7
|
4
|
|
|
4
|
|
34
|
use YAML::XS (); |
|
4
|
|
|
|
|
12
|
|
|
4
|
|
|
|
|
72
|
|
8
|
4
|
|
|
4
|
|
31
|
use Moo; |
|
4
|
|
|
|
|
13
|
|
|
4
|
|
|
|
|
25
|
|
9
|
4
|
|
|
4
|
|
1560
|
use namespace::clean; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
28
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
with 'Catmandu::Exporter'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub add { |
14
|
|
|
|
|
|
|
my ($self, $data) = @_; |
15
|
|
|
|
|
|
|
my $yaml = YAML::XS::Dump($data); |
16
|
|
|
|
|
|
|
utf8::decode($yaml); |
17
|
|
|
|
|
|
|
$self->fh->print($yaml); |
18
|
|
|
|
|
|
|
$self->fh->print("...\n"); |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
1; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
__END__ |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=pod |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 NAME |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
Catmandu::Exporter::YAML - a YAML exporter |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head1 SYNOPSIS |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# From the commandline |
34
|
|
|
|
|
|
|
$ catmandu convert JSON --fix myfixes to YAML < /tmp/data.json |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# From Perl |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
use Catmandu; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# Print to STDOUT |
41
|
|
|
|
|
|
|
my $exporter = Catmandu->exporter('YAML', fix => 'myfix.txt'); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# Print to file or IO::Handle |
44
|
|
|
|
|
|
|
my $exporter = Catmandu->exporter('YAML', file => '/tmp/out.yml'); |
45
|
|
|
|
|
|
|
my $exporter = Catmandu->exporter('YAML', file => $fh); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
$exporter->add_many($arrayref); |
48
|
|
|
|
|
|
|
$exporter->add_many($iterator); |
49
|
|
|
|
|
|
|
$exporter->add_many(sub { }); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
$exporter->add($hashref); |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
printf "exported %d items\n" , $exporter->count; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head1 CONFIGURATION |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=over 4 |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=item file |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
Write output to a local file given by its path or file handle. Alternatively a |
62
|
|
|
|
|
|
|
scalar reference can be passed to write to a string and a code reference can be |
63
|
|
|
|
|
|
|
used to write to a callback function. |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=item fh |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
Write the output to an L<IO::Handle>. If not specified, |
68
|
|
|
|
|
|
|
L<Catmandu::Util::io|Catmandu::Util/IO-functions> is used to create the output |
69
|
|
|
|
|
|
|
handle from the C<file> argument or by using STDOUT. |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=item fix |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
An ARRAY of one or more fixes or file scripts to be applied to exported items. |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=item encoding |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
Binmode of the output stream C<fh>. Set to "C<:utf8>" by default. |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=back |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 SEE ALSO |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
L<Catmandu::Exporter>, L<Catmandu::Importer::YAML> |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=cut |