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