line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package TSVRPC::Parser; |
2
|
7
|
|
|
7
|
|
31158
|
use strict; |
|
7
|
|
|
|
|
12
|
|
|
7
|
|
|
|
|
224
|
|
3
|
7
|
|
|
7
|
|
32
|
use warnings; |
|
7
|
|
|
|
|
13
|
|
|
7
|
|
|
|
|
173
|
|
4
|
7
|
|
|
7
|
|
34
|
use base qw/Exporter/; |
|
7
|
|
|
|
|
10
|
|
|
7
|
|
|
|
|
796
|
|
5
|
7
|
|
|
7
|
|
5974
|
use URI::Escape qw/uri_escape uri_unescape/; |
|
7
|
|
|
|
|
10147
|
|
|
7
|
|
|
|
|
542
|
|
6
|
7
|
|
|
7
|
|
6625
|
use MIME::QuotedPrint qw/encode_qp decode_qp/; |
|
7
|
|
|
|
|
13407
|
|
|
7
|
|
|
|
|
438
|
|
7
|
7
|
|
|
7
|
|
46
|
use MIME::Base64 qw/encode_base64 decode_base64/; |
|
7
|
|
|
|
|
13
|
|
|
7
|
|
|
|
|
3481
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our @EXPORT = qw/encode_tsvrpc decode_tsvrpc/; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
my %ENCODERS = ( |
12
|
|
|
|
|
|
|
'U' => \&uri_escape, |
13
|
|
|
|
|
|
|
'Q' => sub { encode_qp($_[0], '') }, |
14
|
|
|
|
|
|
|
'B' => sub { encode_base64($_[0], '') }, |
15
|
|
|
|
|
|
|
); |
16
|
|
|
|
|
|
|
my %DECODERS = ( |
17
|
|
|
|
|
|
|
'U' => \&uri_unescape, |
18
|
|
|
|
|
|
|
'Q' => sub { decode_qp($_[0]) }, |
19
|
|
|
|
|
|
|
'B' => sub { decode_base64($_[0]) }, |
20
|
|
|
|
|
|
|
); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub encode_tsvrpc { |
23
|
4
|
|
|
4
|
1
|
823
|
my ($data, $encoding) = @_; |
24
|
4
|
100
|
|
2
|
|
17
|
my $encoder = $encoding ? $ENCODERS{$encoding} : sub { $_[0] }; |
|
2
|
|
|
|
|
10
|
|
25
|
4
|
|
|
|
|
6
|
my @res; |
26
|
4
|
|
|
|
|
17
|
while (my ($k, $v) = each %$data){ |
27
|
4
|
|
|
|
|
19
|
push @res, (scalar($encoder->($k)) . "\t" . scalar($encoder->($v))); |
28
|
|
|
|
|
|
|
} |
29
|
4
|
|
|
|
|
80
|
return join "\n", @res; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub decode_tsvrpc { |
33
|
4
|
|
|
4
|
1
|
1155
|
my ($data, $encoding) = @_; |
34
|
4
|
100
|
|
2
|
|
19
|
my $decoder = $encoding ? $DECODERS{$encoding} : sub { $_[0] }; |
|
2
|
|
|
|
|
6
|
|
35
|
4
|
|
|
|
|
7
|
my %res; |
36
|
4
|
|
|
|
|
15
|
for my $line (split "\n", $data) { |
37
|
4
|
|
|
|
|
14
|
my ($k, $v) = map { scalar $decoder->($_) } split("\t", $line); |
|
8
|
|
|
|
|
34
|
|
38
|
4
|
|
|
|
|
37
|
$res{$k} = $v; |
39
|
|
|
|
|
|
|
} |
40
|
4
|
50
|
|
|
|
36
|
return wantarray ? %res : \%res; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
1; |
44
|
|
|
|
|
|
|
__END__ |