line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Record::Serialize::Encode::yaml; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: encode a record as YAML |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
558
|
use v5.12; |
|
1
|
|
|
|
|
4
|
|
6
|
1
|
|
|
1
|
|
537
|
use Moo::Role; |
|
1
|
|
|
|
|
13517
|
|
|
1
|
|
|
|
|
4
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
523
|
use Data::Record::Serialize::Error { errors => ['yaml_backend'] }, -all; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
9
|
|
9
|
1
|
|
|
1
|
|
829
|
use Types::Standard qw[ Enum ]; |
|
1
|
|
|
|
|
114610
|
|
|
1
|
|
|
|
|
7
|
|
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
3330
|
use JSON::PP; # needed for JSON::PP::true/false |
|
1
|
|
|
|
|
15107
|
|
|
1
|
|
|
|
|
100
|
|
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
8
|
use namespace::clean; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
15
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $VERSION = '1.05'; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
BEGIN { |
18
|
1
|
|
|
1
|
|
642
|
my $YAML_XS_VERSION = 0.67; |
19
|
|
|
|
|
|
|
|
20
|
1
|
50
|
|
|
|
4
|
if ( eval { require YAML::XS; YAML::XS->VERSION( $YAML_XS_VERSION ); 1; } ) { |
|
1
|
0
|
|
|
|
485
|
|
|
1
|
|
|
|
|
2685
|
|
|
1
|
|
|
|
|
6
|
|
21
|
|
|
|
|
|
|
*encode = sub { |
22
|
|
|
|
|
|
|
## no critic (Variables::ProhibitPackageVars) |
23
|
2
|
|
|
2
|
|
11
|
local $YAML::XS::Boolean = 'JSON::PP'; |
24
|
2
|
|
|
1
|
|
103
|
YAML::XS::Dump( $_[1] ); |
|
1
|
|
|
1
|
|
49
|
|
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
125
|
|
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
84
|
|
25
|
1
|
|
|
|
|
110
|
}; |
26
|
|
|
|
|
|
|
} |
27
|
0
|
|
|
|
|
0
|
elsif ( eval { require YAML::PP } ) { |
28
|
0
|
|
|
|
|
0
|
my $processor = YAML::PP->new( boolean => 'JSON::PP' ); |
29
|
0
|
|
|
|
|
0
|
*encode = sub { $processor->dump_string( $_[1] ) }; |
|
0
|
|
|
|
|
0
|
|
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
else { |
32
|
0
|
|
|
|
|
0
|
error( 'yaml_backend', |
33
|
|
|
|
|
|
|
"can't find either YAML::XS (>= $YAML_XS_VERSION) or YAML::PP. Please install one of them" ); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
has '+numify' => ( is => 'ro', default => 1 ); |
38
|
|
|
|
|
|
|
has '+stringify' => ( is => 'ro', default => 1 ); |
39
|
|
|
|
|
|
|
|
40
|
2
|
|
|
2
|
|
17
|
sub _needs_eol { 1 } |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
|
50
|
1
|
50
|
|
1
|
1
|
12
|
sub to_bool { $_[1] ? JSON::PP::true : JSON::PP::false } |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
with 'Data::Record::Serialize::Role::Encode'; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
1; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# |
62
|
|
|
|
|
|
|
# This file is part of Data-Record-Serialize |
63
|
|
|
|
|
|
|
# |
64
|
|
|
|
|
|
|
# This software is Copyright (c) 2017 by Smithsonian Astrophysical Observatory. |
65
|
|
|
|
|
|
|
# |
66
|
|
|
|
|
|
|
# This is free software, licensed under: |
67
|
|
|
|
|
|
|
# |
68
|
|
|
|
|
|
|
# The GNU General Public License, Version 3, June 2007 |
69
|
|
|
|
|
|
|
# |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
__END__ |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=pod |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=for :stopwords Diab Jerius Smithsonian Astrophysical Observatory |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head1 NAME |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
Data::Record::Serialize::Encode::yaml - encode a record as YAML |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 VERSION |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
version 1.05 |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 SYNOPSIS |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
use Data::Record::Serialize; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
my $s = Data::Record::Serialize->new( encode => 'yaml', ... ); |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
$s->send( \%record ); |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 DESCRIPTION |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
B<Data::Record::Serialize::Encode::yaml> encodes a record as YAML. It uses uses either L<YAML::XS> or L<YAML::PP>. |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
It performs the L<Data::Record::Serialize::Role::Encode> role. |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 METHODS |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head2 to_bool |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
$bool = $self->to_bool( $truthy ); |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
Convert a truthy value to something that the YAML encoders will recognize as a boolean. |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head1 INTERNALS |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=for Pod::Coverage encode |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=for Pod::Coverage numify |
112
|
|
|
|
|
|
|
stringify |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 CONSTRUCTOR OPTIONS |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=over |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=item backend => C<YAML::XS> | C<YAML::PP> |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Optional. Which YAML backend to use. If not specified, searches for one of the two. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=back |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head1 SUPPORT |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head2 Bugs |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Please report any bugs or feature requests to bug-data-record-serialize@rt.cpan.org or through the web interface at: L<https://rt.cpan.org/Public/Dist/Display.html?Name=Data-Record-Serialize> |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head2 Source |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
Source is available at |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
https://gitlab.com/djerius/data-record-serialize |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
and may be cloned from |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
https://gitlab.com/djerius/data-record-serialize.git |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head1 SEE ALSO |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
Please see those modules/websites for more information related to this module. |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=over 4 |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=item * |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
L<Data::Record::Serialize|Data::Record::Serialize> |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=back |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head1 AUTHOR |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
Diab Jerius <djerius@cpan.org> |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
This software is Copyright (c) 2017 by Smithsonian Astrophysical Observatory. |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
This is free software, licensed under: |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
The GNU General Public License, Version 3, June 2007 |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=cut |