line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id: /mirror/perl/Data-Decode/trunk/lib/Data/Decode.pm 8881 2007-11-09T10:28:54.182349Z daisuke $ |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# Copyright (c) 2007 Daisuke Maki |
4
|
|
|
|
|
|
|
# All rights reserved. |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
package Data::Decode; |
7
|
5
|
|
|
5
|
|
199866
|
use strict; |
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
225
|
|
8
|
5
|
|
|
5
|
|
27
|
use warnings; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
179
|
|
9
|
5
|
|
|
5
|
|
34
|
use base qw(Class::Accessor::Fast); |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
8656
|
|
10
|
5
|
|
|
5
|
|
32747
|
use Carp (); |
|
5
|
|
|
|
|
14
|
|
|
5
|
|
|
|
|
231
|
|
11
|
5
|
|
|
5
|
|
5569
|
use Data::Decode::Exception; |
|
5
|
|
|
|
|
21
|
|
|
5
|
|
|
|
|
3470
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors($_) for qw(_decoder); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $VERSION = '0.00006'; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub new |
18
|
|
|
|
|
|
|
{ |
19
|
3
|
|
|
3
|
1
|
63
|
my $class = shift; |
20
|
3
|
|
|
|
|
14
|
my %args = @_; |
21
|
3
|
|
|
|
|
9
|
my $self = bless {}, $class; |
22
|
3
|
|
|
|
|
48
|
$self->decoder($args{strategy}); |
23
|
|
|
|
|
|
|
|
24
|
3
|
|
|
|
|
12
|
return $self; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub decoder |
28
|
|
|
|
|
|
|
{ |
29
|
17
|
|
|
17
|
1
|
2974
|
my $self = shift; |
30
|
|
|
|
|
|
|
|
31
|
17
|
|
|
|
|
26
|
my $ret; |
32
|
17
|
100
|
|
|
|
53
|
if (! @_) { |
33
|
14
|
|
|
|
|
54
|
$ret = $self->_decoder(); |
34
|
|
|
|
|
|
|
} else { |
35
|
3
|
|
33
|
|
|
50
|
$ret = $self->_decoder($_[0] || Carp::croak("No strategy specified") ); |
36
|
3
|
50
|
|
|
|
47
|
if (! eval { $_[0]->can('decode') }) { |
|
3
|
|
|
|
|
73
|
|
37
|
0
|
|
|
|
|
0
|
Carp::croak("$_[0] does not implement a 'decode' method"); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
} |
40
|
17
|
|
|
|
|
161
|
return $ret; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub decode |
44
|
|
|
|
|
|
|
{ |
45
|
10
|
|
|
10
|
1
|
5215
|
my ($self, $data, $hints) = @_; |
46
|
|
|
|
|
|
|
|
47
|
10
|
50
|
|
|
|
37
|
return () unless defined $data; |
48
|
10
|
|
50
|
|
|
62
|
$hints ||= {}; |
49
|
|
|
|
|
|
|
|
50
|
10
|
|
|
|
|
19
|
my $ret = eval { |
51
|
10
|
|
|
|
|
33
|
$self->decoder->decode($self, $data, $hints); |
52
|
|
|
|
|
|
|
}; |
53
|
10
|
|
|
|
|
155
|
my $e; |
54
|
10
|
50
|
|
|
|
70
|
if ($e = Data::Decode::Exception::Deferred->caught() ) { |
|
|
50
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# Just deferred. return () |
56
|
0
|
|
|
|
|
0
|
return (); |
57
|
|
|
|
|
|
|
} elsif ( $e = Exception::Class->caught() ) { |
58
|
|
|
|
|
|
|
# Oh, this we re-throw |
59
|
0
|
0
|
|
|
|
0
|
eval { $e->isa('Data::Decode::Exception') } ? |
|
0
|
|
|
|
|
0
|
|
60
|
|
|
|
|
|
|
$e->rethrow : die $e; |
61
|
|
|
|
|
|
|
} |
62
|
10
|
|
|
|
|
185
|
return $ret; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
1; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
__END__ |