line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Moxy::Util; |
2
|
14
|
|
|
14
|
|
78
|
use strict; |
|
14
|
|
|
|
|
66
|
|
|
14
|
|
|
|
|
512
|
|
3
|
14
|
|
|
14
|
|
75
|
use warnings; |
|
14
|
|
|
|
|
26
|
|
|
14
|
|
|
|
|
3380
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
# ------------------------------------------------------------------------- |
6
|
|
|
|
|
|
|
# detect response charset. |
7
|
|
|
|
|
|
|
# see Plagger::Util |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
my $Detector; |
10
|
|
|
|
|
|
|
BEGIN { |
11
|
14
|
50
|
|
14
|
|
32
|
if ( eval { require Jcode; 1 } ) { |
|
14
|
50
|
|
|
|
6469
|
|
|
0
|
|
|
|
|
0
|
|
12
|
0
|
|
|
|
|
0
|
$Detector = sub { my ($code, $nmatch) = Jcode::getcode($_[0]); $code }; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
13
|
14
|
|
|
|
|
13103
|
} elsif ( eval { require Encode::Detect::Detector; 1 } ) { |
|
14
|
|
|
|
|
47318
|
|
14
|
14
|
|
|
|
|
4870
|
$Detector = sub { Encode::Detect::Detector::detect($_[0]) }; |
|
0
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
} else { |
16
|
0
|
|
|
|
|
|
require Encode::Guess; |
17
|
|
|
|
|
|
|
$Detector = sub { |
18
|
0
|
|
|
|
|
|
my @guess = qw(utf-8 euc-jp shift_jis); # xxx japanese only? |
19
|
0
|
|
|
|
|
|
eval { Encode::Guess::guess_encoding($_[0], @guess)->name }; |
|
0
|
|
|
|
|
|
|
20
|
0
|
|
|
|
|
|
}; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub HTTP::Response::charset { |
25
|
0
|
|
|
0
|
1
|
|
my ($self, ) = @_; |
26
|
|
|
|
|
|
|
|
27
|
0
|
|
0
|
|
|
|
return $self->{__charset} ||= do { |
28
|
0
|
|
|
|
|
|
my $charset; |
29
|
0
|
0
|
|
|
|
|
if ( $self->header('Content-Type') =~ /charset=([\w\-]+)/io ) { |
30
|
0
|
|
|
|
|
|
$charset = $1; |
31
|
|
|
|
|
|
|
} |
32
|
0
|
|
0
|
|
|
|
$charset ||= ( $self->content() =~ /<\?xml version="1.0" encoding="([\w\-]+)"\?>/ )[0]; |
33
|
0
|
|
0
|
|
|
|
$charset ||= ( $self->content() =~ m!
|
34
|
0
|
|
0
|
|
|
|
$charset ||= $Detector->( $self->content() ); |
35
|
0
|
|
0
|
|
|
|
$charset ||= 'cp932'; |
36
|
0
|
|
|
|
|
|
$charset; |
37
|
|
|
|
|
|
|
}; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
1; |
41
|
|
|
|
|
|
|
__END__ |