line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Object::FromData::Hash; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
9
|
use strict; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
59
|
|
4
|
3
|
|
|
3
|
|
8
|
use warnings; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
50
|
|
5
|
3
|
|
|
3
|
|
9
|
use Digest::MD5 'md5_hex'; # convenience, not security |
|
3
|
|
|
|
|
2
|
|
|
3
|
|
|
|
|
406
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub _new { |
8
|
3
|
|
|
3
|
|
3
|
my ( $class, $arg_for ) = @_; |
9
|
|
|
|
|
|
|
|
10
|
3
|
|
|
|
|
4
|
my $hashref = $arg_for->{ref}; |
11
|
3
|
|
50
|
|
|
12
|
my $allow_private = $arg_for->{allow_private} || 0; |
12
|
3
|
|
|
|
|
14
|
my @all_keys = sort CORE::keys %$hashref; |
13
|
3
|
50
|
|
|
|
7
|
my @keys = $allow_private ? @all_keys : grep { !/^_/ } @all_keys; |
|
9
|
|
|
|
|
18
|
|
14
|
|
|
|
|
|
|
|
15
|
3
|
|
|
|
|
16
|
my $new_class = "${class}::" . md5_hex( join '-' => @keys ); |
16
|
|
|
|
|
|
|
{ |
17
|
3
|
|
|
3
|
|
14
|
no strict 'refs'; |
|
3
|
|
|
|
|
25
|
|
|
3
|
|
|
|
|
479
|
|
|
3
|
|
|
|
|
4
|
|
18
|
3
|
|
|
|
|
2
|
@{"${new_class}::ISA"} = $class; |
|
3
|
|
|
|
|
36
|
|
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
3
|
|
|
|
|
2
|
my %hash; |
22
|
3
|
|
|
|
|
9
|
my $self = { |
23
|
|
|
|
|
|
|
hash => \%hash, |
24
|
|
|
|
|
|
|
keys => \@keys, |
25
|
|
|
|
|
|
|
allow_private => $allow_private, |
26
|
|
|
|
|
|
|
current_index => 0, |
27
|
|
|
|
|
|
|
}; |
28
|
|
|
|
|
|
|
|
29
|
3
|
|
|
|
|
5
|
KEY: foreach my $key (@all_keys) { |
30
|
9
|
|
|
|
|
7
|
my $value = $hashref->{$key}; |
31
|
9
|
100
|
|
|
|
18
|
if ( !ref $value ) { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
32
|
7
|
|
|
|
|
19
|
$hash{$key} = $value; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
elsif ( 'ARRAY' eq ref $value ) { |
35
|
1
|
|
|
|
|
8
|
$hash{$key} |
36
|
|
|
|
|
|
|
= Object::FromData::Array->_new( { ref => $value } ); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
elsif ( 'HASH' eq ref $value ) { |
39
|
1
|
|
|
|
|
7
|
$hash{$key} = $class->_new( { ref => $value } ); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
else { |
42
|
0
|
|
|
|
|
0
|
die "Don't yet handle $value"; |
43
|
|
|
|
|
|
|
} |
44
|
9
|
100
|
|
|
|
18
|
if ( $key =~ /^_/ ) { |
45
|
1
|
50
|
|
|
|
3
|
next KEY unless $allow_private; |
46
|
|
|
|
|
|
|
} |
47
|
3
|
|
|
3
|
|
14
|
no strict 'refs'; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
688
|
|
48
|
8
|
|
|
5
|
|
15
|
*{"$new_class::$key"} = sub { $hash{$key} }; |
|
8
|
|
|
|
|
28
|
|
|
5
|
|
|
|
|
420
|
|
49
|
|
|
|
|
|
|
} |
50
|
3
|
|
|
|
|
12
|
return bless $self => $new_class; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub keys { |
54
|
1
|
|
|
1
|
1
|
3
|
my $self = shift; |
55
|
1
|
50
|
|
|
|
3
|
$self = shift if @_; |
56
|
1
|
|
|
|
|
1
|
return keys %{ $self->{hash} }; |
|
1
|
|
|
|
|
14
|
|
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub values { |
60
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
61
|
0
|
0
|
|
|
|
|
$self = shift if @_; |
62
|
0
|
|
|
|
|
|
return values %{ $self->{hash} }; |
|
0
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
0
|
1
|
|
sub is_hashref {1} |
66
|
|
|
|
0
|
1
|
|
sub is_arrayref { } |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
1; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
__END__ |