| 1 | package Catmandu::Exporter::YAML; | ||
| 2 | |||
| 3 | 4 | ▶ | use Catmandu::Sane; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | |||
| 5 | 2 | our $VERSION = '1.0201_02'; | |
| 6 | |||
| 7 | 4 | ▶ | use YAML::XS (); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | 4 | ▶ | use Moo; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | 4 | ▶ | use namespace::clean; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 10 | |||
| 11 | 2 | with 'Catmandu::Exporter'; | |
| 12 | |||
| 13 | sub add { | ||
| 14 | 5 | ▶ | my ($self, $data) = @_; |
|
Subroutine
add: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 15 | 5 | my $yaml = YAML::XS::Dump($data); | |
| 16 | 5 | utf8::decode($yaml); | |
| 17 | 5 | $self->fh->print($yaml); | |
| 18 | 5 | $self->fh->print("...\n"); | |
| 19 | } | ||
| 20 | |||
| 21 | 2 | 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::Exporter::YAML; | ||
| 39 | |||
| 40 | # Print to STDOUT | ||
| 41 | my $exporter = Catmandu::Exporter::YAML->new(fix => 'myfix.txt'); | ||
| 42 | |||
| 43 | # Print to file or IO::Handle | ||
| 44 | my $exporter = Catmandu::Exporter::YAML->new(file => '/tmp/out.yml'); | ||
| 45 | my $exporter = Catmandu::Exporter::YAML->new(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 objects\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 | ||