line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
package Data::Decode::Encode::Guess; |
3
|
3
|
|
|
3
|
|
25028
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
use namespace::clean -except => qw(meta); |
5
|
|
|
|
|
|
|
use Encode(); |
6
|
|
|
|
|
|
|
use Encode::Guess(); |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
has encodings => ( |
9
|
|
|
|
|
|
|
is => 'ro', |
10
|
|
|
|
|
|
|
isa => 'ArrayRef', |
11
|
|
|
|
|
|
|
lazy_build => 1, |
12
|
|
|
|
|
|
|
); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub _build_encodings { |
15
|
|
|
|
|
|
|
return []; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub guess_encoding { |
19
|
|
|
|
|
|
|
my ($self, $decoder, $string, $hints) = @_; |
20
|
|
|
|
|
|
|
local $Encode::Guess::NoUTFAutoGuess = 1; |
21
|
|
|
|
|
|
|
return Encode::Guess::guess_encoding( |
22
|
|
|
|
|
|
|
$string, |
23
|
|
|
|
|
|
|
@{ $self->encodings } |
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub decode { |
28
|
|
|
|
|
|
|
my ($self, $decoder, $string, $hints) = @_; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
my $guess = $self->guess_encoding($decoder, $string, $hints); |
31
|
|
|
|
|
|
|
if (! ref $guess) { |
32
|
|
|
|
|
|
|
Data::Decode::Exception::Deferred->throw($guess); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
return eval { $guess->decode( $string ) } || |
36
|
|
|
|
|
|
|
Data::Decode::Exception::Deferred->throw("Failed to decode string from " . $guess->name . ": $@") |
37
|
|
|
|
|
|
|
; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
1; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
__END__ |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head1 NAME |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
Data::Decode::Encode::Guess - Generic Encode::Guess Decoder |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head1 SYNOPSIS |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
Data::Decode->new( |
51
|
|
|
|
|
|
|
strategy => Data::Decode::Encode::Guess->new( |
52
|
|
|
|
|
|
|
encodings => [ $enc1, $enc2, $enc3 ] |
53
|
|
|
|
|
|
|
) |
54
|
|
|
|
|
|
|
); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head1 METHODS |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head2 new |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head2 decode |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=cut |