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