| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
2
|
|
|
2
|
|
163825
|
use strict; |
|
|
2
|
|
|
|
|
6
|
|
|
|
2
|
|
|
|
|
90
|
|
|
2
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
297
|
|
|
3
|
|
|
|
|
|
|
package YAML::PP::Schema::Binary; |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = 'v0.39.0'; # VERSION |
|
6
|
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
1015
|
use MIME::Base64 qw/ decode_base64 encode_base64 /; |
|
|
2
|
|
|
|
|
1659
|
|
|
|
2
|
|
|
|
|
153
|
|
|
8
|
2
|
|
|
2
|
|
397
|
use YAML::PP::Common qw/ YAML_ANY_SCALAR_STYLE /; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
642
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub register { |
|
11
|
1
|
|
|
1
|
1
|
4
|
my ($self, %args) = @_; |
|
12
|
1
|
|
|
|
|
2
|
my $schema = $args{schema}; |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
$schema->add_resolver( |
|
15
|
|
|
|
|
|
|
tag => 'tag:yaml.org,2002:binary', |
|
16
|
|
|
|
|
|
|
match => [ all => sub { |
|
17
|
15
|
|
|
15
|
|
23
|
my ($constructor, $event) = @_; |
|
18
|
15
|
|
|
|
|
25
|
my $base64 = $event->{value}; |
|
19
|
15
|
|
|
|
|
47
|
my $binary = decode_base64($base64); |
|
20
|
15
|
|
|
|
|
43
|
return $binary; |
|
21
|
1
|
|
|
|
|
7
|
}], |
|
22
|
|
|
|
|
|
|
implicit => 0, |
|
23
|
|
|
|
|
|
|
); |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
$schema->add_representer( |
|
26
|
|
|
|
|
|
|
regex => qr{.*}, |
|
27
|
|
|
|
|
|
|
code => sub { |
|
28
|
20
|
|
|
20
|
|
33
|
my ($rep, $node) = @_; |
|
29
|
20
|
|
|
|
|
30
|
my $binary = $node->{value}; |
|
30
|
20
|
100
|
|
|
|
66
|
unless ($binary =~ m/[\x{7F}-\x{10FFFF}]/) { |
|
31
|
|
|
|
|
|
|
# ASCII |
|
32
|
2
|
|
|
|
|
6
|
return; |
|
33
|
|
|
|
|
|
|
} |
|
34
|
18
|
100
|
|
|
|
47
|
if (utf8::is_utf8($binary)) { |
|
35
|
|
|
|
|
|
|
# utf8 |
|
36
|
4
|
|
|
|
|
12
|
return; |
|
37
|
|
|
|
|
|
|
} |
|
38
|
|
|
|
|
|
|
# everything else must be base64 encoded |
|
39
|
14
|
|
|
|
|
45
|
my $base64 = encode_base64($binary); |
|
40
|
14
|
|
|
|
|
27
|
$node->{style} = YAML_ANY_SCALAR_STYLE; |
|
41
|
14
|
|
|
|
|
26
|
$node->{data} = $base64; |
|
42
|
14
|
|
|
|
|
21
|
$node->{tag} = "tag:yaml.org,2002:binary"; |
|
43
|
14
|
|
|
|
|
43
|
return 1; |
|
44
|
|
|
|
|
|
|
}, |
|
45
|
1
|
|
|
|
|
7
|
); |
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
1; |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
__END__ |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=pod |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=encoding utf-8 |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head1 NAME |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
YAML::PP::Schema::Binary - Schema for loading and binary data |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
use YAML::PP; |
|
63
|
|
|
|
|
|
|
my $yp = YAML::PP->new( schema => [qw/ + Binary /] ); |
|
64
|
|
|
|
|
|
|
# or |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
my ($binary, $same_binary) = $yp->load_string(<<'EOM'); |
|
67
|
|
|
|
|
|
|
--- !!binary "\ |
|
68
|
|
|
|
|
|
|
R0lGODlhDAAMAIQAAP//9/X17unp5WZmZgAAAOfn515eXvPz7Y6OjuDg4J+fn5\ |
|
69
|
|
|
|
|
|
|
OTk6enp56enmlpaWNjY6Ojo4SEhP/++f/++f/++f/++f/++f/++f/++f/++f/+\ |
|
70
|
|
|
|
|
|
|
+f/++f/++f/++f/++f/++SH+Dk1hZGUgd2l0aCBHSU1QACwAAAAADAAMAAAFLC\ |
|
71
|
|
|
|
|
|
|
AgjoEwnuNAFOhpEMTRiggcz4BNJHrv/zCFcLiwMWYNG84BwwEeECcgggoBADs=" |
|
72
|
|
|
|
|
|
|
--- !!binary | |
|
73
|
|
|
|
|
|
|
R0lGODlhDAAMAIQAAP//9/X17unp5WZmZgAAAOfn515eXvPz7Y6OjuDg4J+fn5 |
|
74
|
|
|
|
|
|
|
OTk6enp56enmlpaWNjY6Ojo4SEhP/++f/++f/++f/++f/++f/++f/++f/++f/+ |
|
75
|
|
|
|
|
|
|
+f/++f/++f/++f/++f/++SH+Dk1hZGUgd2l0aCBHSU1QACwAAAAADAAMAAAFLC |
|
76
|
|
|
|
|
|
|
AgjoEwnuNAFOhpEMTRiggcz4BNJHrv/zCFcLiwMWYNG84BwwEeECcgggoBADs= |
|
77
|
|
|
|
|
|
|
# The binary value above is a tiny arrow encoded as a gif image. |
|
78
|
|
|
|
|
|
|
EOM |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
See <https://yaml.org/type/binary.html> |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
By prepending a base64 encoded binary string with the C<!!binary> tag, it can |
|
85
|
|
|
|
|
|
|
be automatically decoded when loading. |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
Note that the logic for dumping is probably broken, see |
|
88
|
|
|
|
|
|
|
L<https://github.com/perlpunk/YAML-PP-p5/issues/28>. |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
Suggestions welcome. |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head1 METHODS |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=over |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=item register |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Called by L<YAML::PP::Schema> |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=back |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=cut |