line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
2
|
|
|
2
|
|
1205
|
use 5.008; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
74
|
|
2
|
2
|
|
|
2
|
|
9
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
51
|
|
3
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
113
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Data::Pack; |
6
|
|
|
|
|
|
|
BEGIN { |
7
|
2
|
|
|
2
|
|
34
|
$Data::Pack::VERSION = '1.101611'; |
8
|
|
|
|
|
|
|
} |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# ABSTRACT: Pack data structures so only real content remains |
11
|
2
|
|
|
2
|
|
10
|
use Scalar::Util 'reftype'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
270
|
|
12
|
2
|
|
|
2
|
|
10
|
use Exporter qw(import); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
940
|
|
13
|
|
|
|
|
|
|
our %EXPORT_TAGS = (util => [qw(pack_data pack_hash pack_array has_content)],); |
14
|
|
|
|
|
|
|
our @EXPORT_OK = @{ $EXPORT_TAGS{all} = [ map { @$_ } values %EXPORT_TAGS ] }; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub has_content { |
17
|
43
|
|
|
43
|
1
|
47
|
my $data = shift; |
18
|
43
|
100
|
|
|
|
163
|
return defined $data unless ref $data; |
19
|
19
|
|
|
|
|
43
|
my $type = reftype $data; |
20
|
19
|
100
|
|
|
|
67
|
return @$data if $type eq 'ARRAY'; |
21
|
9
|
50
|
|
|
|
57
|
return keys %$data if $type eq 'HASH'; |
22
|
0
|
|
|
|
|
0
|
die "has_content: unknown type [$type]\n"; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub pack_data { |
26
|
81
|
|
|
81
|
1
|
939
|
my $data = shift; |
27
|
81
|
100
|
|
|
|
183
|
return $data unless ref $data; |
28
|
27
|
|
|
|
|
59
|
my $type = reftype $data; |
29
|
27
|
100
|
|
|
|
68
|
if ($type eq 'HASH') { |
|
|
50
|
|
|
|
|
|
30
|
17
|
|
|
|
|
27
|
my $packed_hash = {}; |
31
|
17
|
|
|
|
|
65
|
while (my ($key, $value) = each %$data) { |
32
|
43
|
|
|
|
|
83
|
my $packed_value = pack_data($value); |
33
|
43
|
100
|
|
|
|
72
|
next unless has_content($packed_value); |
34
|
18
|
|
|
|
|
70
|
$packed_hash->{$key} = $packed_value; |
35
|
|
|
|
|
|
|
} |
36
|
17
|
100
|
|
|
|
45
|
bless $packed_hash, ref $data unless ref $data eq 'HASH'; |
37
|
17
|
100
|
|
|
|
63
|
return wantarray ? %$packed_hash : $packed_hash; |
38
|
|
|
|
|
|
|
} elsif ($type eq 'ARRAY') { |
39
|
34
|
|
|
|
|
74
|
my $packed_array = |
40
|
10
|
|
|
|
|
19
|
[ grep { defined } map { scalar(pack_data($_)) } @$data ]; |
|
34
|
|
|
|
|
54
|
|
41
|
10
|
50
|
|
|
|
32
|
return wantarray ? @$packed_array : $packed_array; |
42
|
|
|
|
|
|
|
} else { |
43
|
0
|
|
|
|
|
0
|
die "pack_hash: unknown type [$type]\n"; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub pack_hash { |
48
|
1
|
|
|
1
|
1
|
8
|
my %h = @_; |
49
|
1
|
|
|
|
|
5
|
pack_data(\%h); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub pack_array { |
53
|
0
|
|
|
0
|
1
|
|
pack_data(\@_); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
1; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
__END__ |