line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Dumper::AutoEncode; |
2
|
3
|
|
|
3
|
|
208837
|
use strict; |
|
3
|
|
|
|
|
24
|
|
|
3
|
|
|
|
|
90
|
|
3
|
3
|
|
|
3
|
|
17
|
use warnings; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
73
|
|
4
|
3
|
|
|
3
|
|
19
|
use Carp (); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
39
|
|
5
|
3
|
|
|
3
|
|
1775
|
use Encode (); |
|
3
|
|
|
|
|
31501
|
|
|
3
|
|
|
|
|
86
|
|
6
|
3
|
|
|
3
|
|
22
|
use Scalar::Util qw(blessed refaddr); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
173
|
|
7
|
3
|
|
|
3
|
|
22
|
use B; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
98
|
|
8
|
3
|
|
|
3
|
|
1816
|
use Data::Dumper; # Dumper |
|
3
|
|
|
|
|
18820
|
|
|
3
|
|
|
|
|
191
|
|
9
|
3
|
|
|
3
|
|
1452
|
use parent qw/Exporter/; |
|
3
|
|
|
|
|
888
|
|
|
3
|
|
|
|
|
19
|
|
10
|
|
|
|
|
|
|
our @EXPORT = qw/eDumper Dumper/; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '0.99'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $ENCODING = ''; |
15
|
|
|
|
|
|
|
our $CHECK_ALREADY_ENCODED = 0; |
16
|
|
|
|
|
|
|
our $DO_NOT_PROCESS_NUMERIC_VALUE = 1; |
17
|
|
|
|
|
|
|
our $FLAG_STR = ''; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our $BEFORE_HOOK; |
20
|
|
|
|
|
|
|
our $AFTER_HOOK; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub _dump { |
23
|
8
|
|
|
8
|
|
35
|
my $d = Data::Dumper->new(\@_); |
24
|
8
|
|
|
|
|
230
|
return $d->Dump; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub eDumper { |
28
|
8
|
|
|
8
|
1
|
13740
|
my @args; |
29
|
8
|
|
|
|
|
20
|
for my $arg (@_) { |
30
|
9
|
|
100
|
|
|
46
|
push @args, encode($ENCODING || 'utf8', $arg); |
31
|
|
|
|
|
|
|
} |
32
|
8
|
|
|
|
|
23
|
_dump(@args); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub encode { |
36
|
9
|
|
|
9
|
1
|
22
|
my ($encoding, $stuff, $check) = @_; |
37
|
9
|
|
33
|
|
|
60
|
$encoding = Encode::find_encoding($encoding) |
38
|
|
|
|
|
|
|
|| Carp::croak("unknown encoding '$encoding'"); |
39
|
9
|
|
50
|
|
|
168
|
$check ||= 0; |
40
|
9
|
|
|
8
|
|
48
|
_apply(sub { $encoding->encode($_[0], $check) }, {}, $stuff); |
|
8
|
|
|
|
|
34
|
|
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# copied from Data::Recursive::Encode |
44
|
|
|
|
|
|
|
sub _apply { |
45
|
11
|
|
|
11
|
|
23
|
my $code = shift; |
46
|
11
|
|
|
|
|
17
|
my $seen = shift; |
47
|
|
|
|
|
|
|
|
48
|
11
|
|
|
|
|
16
|
my @retval; |
49
|
11
|
|
|
|
|
23
|
for my $arg (@_) { |
50
|
13
|
100
|
|
|
|
32
|
if(my $ref = ref $arg){ |
51
|
2
|
|
|
|
|
7
|
my $refaddr = refaddr($arg); |
52
|
2
|
|
|
|
|
4
|
my $proto; |
53
|
|
|
|
|
|
|
|
54
|
2
|
50
|
0
|
|
|
12
|
if(defined($proto = $seen->{$refaddr})){ |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# noop |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
elsif($ref eq 'ARRAY'){ |
58
|
0
|
|
|
|
|
0
|
$proto = $seen->{$refaddr} = []; |
59
|
0
|
|
|
|
|
0
|
@{$proto} = _apply($code, $seen, @{$arg}); |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
elsif($ref eq 'HASH'){ |
62
|
2
|
|
|
|
|
22
|
$proto = $seen->{$refaddr} = {}; |
63
|
2
|
|
|
|
|
6
|
%{$proto} = _apply($code, $seen, %{$arg}); |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
11
|
|
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
elsif($ref eq 'REF' or $ref eq 'SCALAR'){ |
66
|
0
|
|
|
|
|
0
|
$proto = $seen->{$refaddr} = \do{ my $scalar }; |
|
0
|
|
|
|
|
0
|
|
67
|
0
|
|
|
|
|
0
|
${$proto} = _apply($code, $seen, ${$arg}); |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
else{ # CODE, GLOB, IO, LVALUE etc. |
70
|
0
|
|
|
|
|
0
|
$proto = $seen->{$refaddr} = $arg; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
2
|
|
|
|
|
5
|
push @retval, $proto; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
else{ |
76
|
11
|
100
|
|
|
|
26
|
if (_can_exec($arg)) { |
77
|
8
|
100
|
|
|
|
27
|
push @retval, $FLAG_STR ? $FLAG_STR . _exec($code, $arg) : _exec($code, $arg); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
else { |
80
|
3
|
|
|
|
|
9
|
push @retval, $arg; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
11
|
50
|
|
|
|
70
|
return wantarray ? @retval : $retval[0]; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub _exec { |
89
|
8
|
|
|
8
|
|
18
|
my ($code, $arg) = @_; |
90
|
|
|
|
|
|
|
|
91
|
8
|
100
|
|
|
|
24
|
if (ref $BEFORE_HOOK eq 'CODE') { |
92
|
1
|
|
|
|
|
4
|
$arg = $BEFORE_HOOK->($arg); |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
8
|
|
|
|
|
26
|
my $result = $code->($arg); |
96
|
|
|
|
|
|
|
|
97
|
8
|
100
|
|
|
|
25
|
if (ref $AFTER_HOOK eq 'CODE') { |
98
|
1
|
|
|
|
|
3
|
return $AFTER_HOOK->($result); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
7
|
|
|
|
|
24
|
return $result; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
# copied from Data::Recursive::Encode |
105
|
|
|
|
|
|
|
sub _is_number { |
106
|
11
|
|
|
11
|
|
20
|
my $value = shift; |
107
|
11
|
50
|
|
|
|
23
|
return 0 unless defined $value; |
108
|
|
|
|
|
|
|
|
109
|
11
|
|
|
|
|
44
|
my $b_obj = B::svref_2object(\$value); |
110
|
11
|
|
|
|
|
42
|
my $flags = $b_obj->FLAGS; |
111
|
11
|
100
|
66
|
|
|
81
|
return $flags & ( B::SVp_IOK | B::SVp_NOK ) && !( $flags & B::SVp_POK ) ? 1 : 0; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub _can_exec { |
115
|
11
|
|
|
11
|
|
21
|
my ($arg) = @_; |
116
|
|
|
|
|
|
|
|
117
|
11
|
50
|
|
|
|
24
|
return unless defined($arg); |
118
|
11
|
100
|
66
|
|
|
32
|
return if $DO_NOT_PROCESS_NUMERIC_VALUE && _is_number($arg); |
119
|
10
|
100
|
|
|
|
42
|
return 1 if Encode::is_utf8($arg); |
120
|
3
|
50
|
66
|
|
|
15
|
return 1 if !$CHECK_ALREADY_ENCODED && !Encode::is_utf8($arg); |
121
|
|
|
|
|
|
|
|
122
|
2
|
|
|
|
|
5
|
return; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
1; |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
__END__ |