blib/lib/YAML/PP/Schema/Binary.pm

filter: Statementstmt 100% 33 / 33 Branchbran 100% 4 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 100% 1 / 1 totaltotal 100% 45 / 45 CC 3 SCAR 5.1
CC
3
Cov
100%
__ANON__
3.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.7
« blib/lib/YAML/PP/Schema/Catchall.pm ↑ Summary blib/lib/YAML/PP/Writer/File.pm »
1 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package YAML::PP::Schema::Binary;
4  
5 2 our $VERSION = 'v0.43.0'; # VERSION
6  
7 2 ▶use MIME::Base64 qw/ decode_base64 encode_base64 /;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use YAML::PP::Common qw/ YAML_ANY_SCALAR_STYLE /;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶sub register {
Subroutine register: called CC=1 SCAR=0.0
Pod documented
11 1 my ($self, %args) = @_;
12 1 my $schema = $args{schema};
13  
14 $schema->add_resolver(
15 tag => 'tag:yaml.org,2002:binary',
16 15 ▶ match => [ all => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
17 15 my ($constructor, $event) = @_;
18 15 my $base64 = $event->{value};
19 15 my $binary = decode_base64($base64);
20 15 return $binary;
21 1 }],
22 implicit => 0,
23 );
24  
25 $schema->add_representer(
26 regex => qr{.*},
27 20 ▶ code => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
28 20 my ($rep, $node) = @_;
29 20 my $binary = $node->{value};
30 20 ▶ unless ($binary =~ m/[\x{7F}-\x{10FFFF}]/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($binary =~ /[\x{7F}-\x{10FFFF}]/) 2 18 20
31 # ASCII
32 2 return;
33 }
34 18 ▶ if (utf8::is_utf8($binary)) {
Branch: 1 branch
BranchTrueFalseTotal
if (utf8::is_utf8($binary)) 4 14 18
35 # utf8
36 4 return;
37 }
38 # everything else must be base64 encoded
39 14 my $base64 = encode_base64($binary);
40 14 $node->{style} = YAML_ANY_SCALAR_STYLE;
41 14 $node->{data} = $base64;
42 14 $node->{tag} = "tag:yaml.org,2002:binary";
43 14 return 1;
44 },
45 1 );
46 }
47  
48 2 1;
49  
50 __END__
« blib/lib/YAML/PP/Schema/Catchall.pm ↑ Summary blib/lib/YAML/PP/Writer/File.pm »