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