| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
use Catmandu::Sane; |
|
3
|
5
|
|
|
5
|
|
89751
|
|
|
|
5
|
|
|
|
|
11
|
|
|
|
5
|
|
|
|
|
37
|
|
|
4
|
|
|
|
|
|
|
our $VERSION = '1.2018'; |
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use YAML::XS (); |
|
7
|
5
|
|
|
5
|
|
34
|
use Moo; |
|
|
5
|
|
|
|
|
8
|
|
|
|
5
|
|
|
|
|
93
|
|
|
8
|
5
|
|
|
5
|
|
32
|
use Devel::Peek; |
|
|
5
|
|
|
|
|
9
|
|
|
|
5
|
|
|
|
|
30
|
|
|
9
|
5
|
|
|
5
|
|
7311
|
use namespace::clean; |
|
|
5
|
|
|
|
|
1817
|
|
|
|
5
|
|
|
|
|
44
|
|
|
10
|
5
|
|
|
5
|
|
431
|
|
|
|
5
|
|
|
|
|
12
|
|
|
|
5
|
|
|
|
|
33
|
|
|
11
|
|
|
|
|
|
|
with 'Catmandu::Importer'; |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my $RE_EOF = qr'^\.\.\.$'; |
|
14
|
|
|
|
|
|
|
my $RE_SEP = qr'^---'; |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
my ($self) = @_; |
|
17
|
|
|
|
|
|
|
sub { |
|
18
|
|
|
|
|
|
|
state $fh = $self->fh; |
|
19
|
|
|
|
|
|
|
state $yaml = ""; |
|
20
|
|
|
|
|
|
|
state $data; |
|
21
|
|
|
|
|
|
|
state $line; |
|
22
|
|
|
|
|
|
|
while (defined($line = <$fh>)) { |
|
23
|
|
|
|
|
|
|
if ($line =~ $RE_EOF) { |
|
24
|
|
|
|
|
|
|
last; |
|
25
|
|
|
|
|
|
|
} |
|
26
|
|
|
|
|
|
|
if ($line =~ $RE_SEP && $yaml) { |
|
27
|
|
|
|
|
|
|
utf8::encode($yaml); |
|
28
|
|
|
|
|
|
|
$data = YAML::XS::Load($yaml); |
|
29
|
|
|
|
|
|
|
$yaml = $line; |
|
30
|
|
|
|
|
|
|
return $data; |
|
31
|
|
|
|
|
|
|
} |
|
32
|
|
|
|
|
|
|
$yaml .= $line; |
|
33
|
|
|
|
|
|
|
} |
|
34
|
|
|
|
|
|
|
if ($yaml) { |
|
35
|
|
|
|
|
|
|
utf8::encode($yaml); |
|
36
|
|
|
|
|
|
|
$data = YAML::XS::Load($yaml); |
|
37
|
|
|
|
|
|
|
$yaml = ""; |
|
38
|
|
|
|
|
|
|
return $data; |
|
39
|
|
|
|
|
|
|
} |
|
40
|
|
|
|
|
|
|
return; |
|
41
|
|
|
|
|
|
|
}; |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
1; |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=pod |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head1 NAME |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
Catmandu::Importer::YAML - Package that imports YAML data |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# From the command line |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
$ catmandu convert YAML to JSON < data.yaml |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# In a Perl script |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
use Catmandu; |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
my $importer = Catmandu->importer('YAML',file => "/foo/bar.yaml"); |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
my $n = $importer->each(sub { |
|
66
|
|
|
|
|
|
|
my $hashref = $_[0]; |
|
67
|
|
|
|
|
|
|
# ... |
|
68
|
|
|
|
|
|
|
}); |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
The YAML input file needs to be separated into records: |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
--- |
|
73
|
|
|
|
|
|
|
- recordno: 1 |
|
74
|
|
|
|
|
|
|
- name: Alpha |
|
75
|
|
|
|
|
|
|
--- |
|
76
|
|
|
|
|
|
|
- recordno: 2 |
|
77
|
|
|
|
|
|
|
- name: Beta |
|
78
|
|
|
|
|
|
|
... |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
where '---' is the record separator and '...' the EOF indicator. |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 CONFIGURATION |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=over |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=item file |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Read input from a local file given by its path. Alternatively a scalar |
|
89
|
|
|
|
|
|
|
reference can be passed to read from a string. |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=item fh |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Read input from an L<IO::Handle>. If not specified, L<Catmandu::Util::io> is used to |
|
94
|
|
|
|
|
|
|
create the input stream from the C<file> argument or by using STDIN. |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=item encoding |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Binmode of the input stream C<fh>. Set to C<:utf8> by default. |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=item fix |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
An ARRAY of one or more fixes or file scripts to be applied to imported items. |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=back |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head1 METHODS |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
Every L<Catmandu::Importer> is a L<Catmandu::Iterable> all its methods are |
|
109
|
|
|
|
|
|
|
inherited. The Catmandu::Importer::YAML methods are not idempotent: YAML feeds |
|
110
|
|
|
|
|
|
|
can only be read once. |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
L<Catmandu::Exporter::YAML> |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=cut |