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