line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
570
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
2
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
51
|
|
3
|
|
|
|
|
|
|
package YAML::PP::Schema::Binary; |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.036'; # VERSION |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
457
|
use MIME::Base64 qw/ decode_base64 encode_base64 /; |
|
1
|
|
|
|
|
664
|
|
|
1
|
|
|
|
|
63
|
|
8
|
1
|
|
|
1
|
|
6
|
use YAML::PP::Common qw/ YAML_ANY_SCALAR_STYLE /; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
301
|
|
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
|
|
27
|
my ($constructor, $event) = @_; |
18
|
15
|
|
|
|
|
36
|
my $base64 = $event->{value}; |
19
|
15
|
|
|
|
|
53
|
my $binary = decode_base64($base64); |
20
|
15
|
|
|
|
|
52
|
return $binary; |
21
|
1
|
|
|
|
|
8
|
}], |
22
|
|
|
|
|
|
|
implicit => 0, |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
$schema->add_representer( |
26
|
|
|
|
|
|
|
regex => qr{.*}, |
27
|
|
|
|
|
|
|
code => sub { |
28
|
20
|
|
|
20
|
|
38
|
my ($rep, $node) = @_; |
29
|
20
|
|
|
|
|
35
|
my $binary = $node->{value}; |
30
|
20
|
100
|
|
|
|
87
|
unless ($binary =~ m/[\x{7F}-\x{10FFFF}]/) { |
31
|
|
|
|
|
|
|
# ASCII |
32
|
2
|
|
|
|
|
9
|
return; |
33
|
|
|
|
|
|
|
} |
34
|
18
|
100
|
|
|
|
49
|
if (utf8::is_utf8($binary)) { |
35
|
|
|
|
|
|
|
# utf8 |
36
|
4
|
|
|
|
|
15
|
return; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
# everything else must be base64 encoded |
39
|
14
|
|
|
|
|
47
|
my $base64 = encode_base64($binary); |
40
|
14
|
|
|
|
|
44
|
$node->{style} = YAML_ANY_SCALAR_STYLE; |
41
|
14
|
|
|
|
|
28
|
$node->{data} = $base64; |
42
|
14
|
|
|
|
|
28
|
$node->{tag} = "tag:yaml.org,2002:binary"; |
43
|
14
|
|
|
|
|
47
|
return 1; |
44
|
|
|
|
|
|
|
}, |
45
|
1
|
|
|
|
|
8
|
); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
1; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
__END__ |