line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CBOR::Free::X::WideCharacter; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
756
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
36
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
38
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
5
|
use parent qw( CBOR::Free::X::Base ); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
8
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
474
|
use Text::Control (); |
|
1
|
|
|
|
|
288
|
|
|
1
|
|
|
|
|
173
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub _new { |
11
|
12
|
|
|
12
|
|
573
|
my ($class, $value) = @_; |
12
|
|
|
|
|
|
|
|
13
|
12
|
|
|
|
|
33
|
my $hex = Text::Control::to_hex($value); |
14
|
|
|
|
|
|
|
|
15
|
12
|
|
|
|
|
243
|
$hex = _escape_multibyte($hex); |
16
|
|
|
|
|
|
|
|
17
|
12
|
|
|
|
|
58
|
return $class->SUPER::_new("Cannot encode wide character(s): “$hex”"); |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub _escape_multibyte { |
21
|
12
|
|
|
12
|
|
23
|
my ($value) = @_; |
22
|
|
|
|
|
|
|
|
23
|
12
|
|
|
|
|
44
|
for my $i ( reverse 0 .. (length($value) - 1) ) { |
24
|
88
|
|
|
|
|
150
|
my $chr = substr( $value, $i, 1 ); |
25
|
|
|
|
|
|
|
|
26
|
88
|
100
|
|
|
|
172
|
if (ord $chr > 0xff) { |
27
|
12
|
|
|
|
|
67
|
substr( $value, $i, 1, sprintf "\\x{%x}", ord $chr ); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
12
|
|
|
|
|
37
|
utf8::encode($value); |
32
|
|
|
|
|
|
|
|
33
|
12
|
|
|
|
|
31
|
return "$value"; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
1; |