line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id: /mirror/perl/Data-Decode/trunk/lib/Data/Decode/Chain.pm 4834 2007-11-03T09:22:42.139028Z daisuke $ |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# Copyright (c) 2007 Daisuke Maki |
4
|
|
|
|
|
|
|
# All rights reserved. |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
package Data::Decode::Chain; |
7
|
2
|
|
|
2
|
|
3453
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
77
|
|
8
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
73
|
|
9
|
2
|
|
|
2
|
|
11
|
use base qw(Class::Accessor::Fast); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
160
|
|
10
|
2
|
|
|
2
|
|
9
|
use Data::Decode::Exception; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
573
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors($_) for qw(decoders); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub new |
15
|
|
|
|
|
|
|
{ |
16
|
1
|
|
|
1
|
1
|
17
|
my $class = shift; |
17
|
1
|
|
|
|
|
3
|
my %args = @_; |
18
|
1
|
|
50
|
|
|
5
|
$args{decoders} ||= []; |
19
|
1
|
50
|
|
|
|
7
|
if (ref $args{decoders} ne 'ARRAY') { |
20
|
0
|
|
|
|
|
0
|
$args{decoders} = [ $args{decoders} ]; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
1
|
|
|
|
|
17
|
return $class->SUPER::new({ decoders => $args{decoders} }); |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub decode |
27
|
|
|
|
|
|
|
{ |
28
|
5
|
|
|
5
|
1
|
10
|
my ($self, $decoder, $string, $hints) = @_; |
29
|
|
|
|
|
|
|
|
30
|
5
|
|
|
|
|
7
|
my $ret; |
31
|
5
|
|
|
|
|
9
|
foreach my $decoder (@{ $self->decoders }) { |
|
5
|
|
|
|
|
16
|
|
32
|
8
|
|
|
|
|
32
|
$ret = eval { |
33
|
8
|
|
|
|
|
101
|
$decoder->decode($decoder, $string, $hints); |
34
|
|
|
|
|
|
|
}; |
35
|
8
|
|
|
|
|
1979
|
my $e; |
36
|
8
|
100
|
|
|
|
47
|
if ($e = Data::Decode::Exception::Deferred->caught() ) { |
|
|
50
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# Decoding was deffered, we don't do anything about this |
38
|
|
|
|
|
|
|
# error, and simply let the next decoder attempt to handle |
39
|
|
|
|
|
|
|
# this particular set of inputs. |
40
|
3
|
|
|
|
|
57
|
next; |
41
|
|
|
|
|
|
|
} elsif ( $e = Exception::Class->caught() ) { |
42
|
|
|
|
|
|
|
# This is a generic error, just propagate it |
43
|
0
|
0
|
|
|
|
0
|
eval { $e->isa('Data::Decode::Exception') } ? |
|
0
|
|
|
|
|
0
|
|
44
|
|
|
|
|
|
|
$e->rethrow : die $e; |
45
|
|
|
|
|
|
|
} |
46
|
5
|
|
|
|
|
86
|
last; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
5
|
|
|
|
|
21
|
return $ret; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
1; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
__END__ |