|  line  | 
 stmt  | 
 bran  | 
 cond  | 
 sub  | 
 pod  | 
 time  | 
 code  | 
| 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 # Data::Hopen::Scope::Hash - a hash-based nested key-value store based  | 
| 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 package Data::Hopen::Scope::Hash;  | 
| 
3
 | 
18
 | 
 
 | 
 
 | 
  
18
  
 | 
 
 | 
24337
 | 
 use strict;  | 
| 
 
 | 
18
 | 
 
 | 
 
 | 
 
 | 
 
 | 
41
 | 
    | 
| 
 
 | 
18
 | 
 
 | 
 
 | 
 
 | 
 
 | 
566
 | 
    | 
| 
4
 | 
18
 | 
 
 | 
 
 | 
  
18
  
 | 
 
 | 
107
 | 
 use Data::Hopen::Base;  | 
| 
 
 | 
18
 | 
 
 | 
 
 | 
 
 | 
 
 | 
37
 | 
    | 
| 
 
 | 
18
 | 
 
 | 
 
 | 
 
 | 
 
 | 
110
 | 
    | 
| 
5
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
6
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 our $VERSION = '0.000018';  | 
| 
7
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
8
 | 
18
 | 
 
 | 
 
 | 
  
18
  
 | 
 
 | 
12277
 | 
 use Data::Hopen::Scope qw(:default :internal);  | 
| 
 
 | 
18
 | 
 
 | 
 
 | 
 
 | 
 
 | 
62
 | 
    | 
| 
 
 | 
18
 | 
 
 | 
 
 | 
 
 | 
 
 | 
2634
 | 
    | 
| 
9
 | 
18
 | 
 
 | 
 
 | 
  
18
  
 | 
 
 | 
139
 | 
 use parent 'Data::Hopen::Scope';  | 
| 
 
 | 
18
 | 
 
 | 
 
 | 
 
 | 
 
 | 
40
 | 
    | 
| 
 
 | 
18
 | 
 
 | 
 
 | 
 
 | 
 
 | 
139
 | 
    | 
| 
10
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 use Class::Tiny {  | 
| 
11
 | 
155
 | 
 
 | 
 
 | 
 
 | 
 
 | 
1591
 | 
     _content => sub { +{} },    # Our storage  | 
| 
12
 | 
18
 | 
 
 | 
 
 | 
  
18
  
 | 
 
 | 
1570
 | 
 };  | 
| 
 
 | 
18
 | 
 
 | 
 
 | 
 
 | 
 
 | 
39
 | 
    | 
| 
 
 | 
18
 | 
 
 | 
 
 | 
 
 | 
 
 | 
167
 | 
    | 
| 
13
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
14
 | 
18
 | 
 
 | 
 
 | 
  
18
  
 | 
 
 | 
5168
 | 
 use Data::Hopen qw(getparameters);  | 
| 
 
 | 
18
 | 
 
 | 
 
 | 
 
 | 
 
 | 
47
 | 
    | 
| 
 
 | 
18
 | 
 
 | 
 
 | 
 
 | 
 
 | 
885
 | 
    | 
| 
15
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 #use Data::Hopen::Util::Data qw(clone);  | 
| 
16
 | 
18
 | 
 
 | 
 
 | 
  
18
  
 | 
 
 | 
124
 | 
 use Set::Scalar;  | 
| 
 
 | 
18
 | 
 
 | 
 
 | 
 
 | 
 
 | 
528
 | 
    | 
| 
 
 | 
18
 | 
 
 | 
 
 | 
 
 | 
 
 | 
9592
 | 
    | 
| 
17
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 #use Sub::ScopeFinalizer qw(scope_finalizer);  | 
| 
18
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
19
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 # Docs {{{1  | 
| 
20
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
21
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =head1 NAME  | 
| 
22
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
23
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 Data::Hopen::Scope::Hash - a hash-based nested key-value store  | 
| 
24
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
25
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =head1 SYNOPSIS  | 
| 
26
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
27
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 This class implements L using a single hash table as the  | 
| 
28
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 storage.  It only supports one set of data (L),  | 
| 
29
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 which is named C<0>.  | 
| 
30
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
31
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =head1 ATTRIBUTES  | 
| 
32
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
33
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =head2 outer  | 
| 
34
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
35
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 The fallback C for looking up names not found in this C.  | 
| 
36
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 If non is provided, it is C, and no fallback will happen.  | 
| 
37
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
38
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =head2 name  | 
| 
39
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
40
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 Not used, but provided so you can use L to make Scopes.  | 
| 
41
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
42
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =head1 METHODS  | 
| 
43
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
44
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =cut  | 
| 
45
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
46
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 # }}}1  | 
| 
47
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
48
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =head2 put  | 
| 
49
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
50
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 Add key-value pairs to this scope.  See L.  In this  | 
| 
51
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 particular implementation, the last-added value for a particular key wins.  | 
| 
52
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
53
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 TODO add $set option once it's added to D::H::Scope::put().  | 
| 
54
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
55
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =cut  | 
| 
56
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
57
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub put {  | 
| 
58
 | 
49
 | 
  
100
  
 | 
 
 | 
  
49
  
 | 
  
1
  
 | 
16267
 | 
     my $self = shift or croak 'Need an instance';  | 
| 
59
 | 
48
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
275
 | 
     croak "Got an odd number of parameters" if @_%2;  | 
| 
60
 | 
47
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
131
 | 
     return $self unless @_;  | 
| 
61
 | 
46
 | 
 
 | 
 
 | 
 
 | 
 
 | 
160
 | 
     my %new = @_;  | 
| 
62
 | 
46
 | 
 
 | 
 
 | 
 
 | 
 
 | 
144
 | 
     @{$self->_content}{keys %new} = values %new;  | 
| 
 
 | 
46
 | 
 
 | 
 
 | 
 
 | 
 
 | 
1041
 | 
    | 
| 
63
 | 
46
 | 
 
 | 
 
 | 
 
 | 
 
 | 
186
 | 
     return $self;  | 
| 
64
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 } #add()  | 
| 
65
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
66
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =head2 merge  | 
| 
67
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
68
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 Merge in values.  See L.  | 
| 
69
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
70
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =cut  | 
| 
71
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
72
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub merge {  | 
| 
73
 | 
45
 | 
  
100
  
 | 
 
 | 
  
45
  
 | 
  
1
  
 | 
2671
 | 
     my $self = shift or croak 'Need an instance';  | 
| 
74
 | 
44
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
253
 | 
     croak "Got an odd number of parameters" if @_%2;  | 
| 
75
 | 
43
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
115
 | 
     return unless @_;  | 
| 
76
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
77
 | 
39
 | 
 
 | 
 
 | 
 
 | 
 
 | 
123
 | 
     my %new = @_;  | 
| 
78
 | 
39
 | 
 
 | 
 
 | 
 
 | 
 
 | 
162
 | 
     my $merger = $self->_merger;  | 
| 
79
 | 
39
 | 
 
 | 
 
 | 
 
 | 
 
 | 
936
 | 
     $self->_content($merger->merge($self->_content, \%new));  | 
| 
80
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
81
 | 
39
 | 
 
 | 
 
 | 
 
 | 
 
 | 
3300
 | 
     return $self;  | 
| 
82
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 } #merge()  | 
| 
83
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
84
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =head2 adopt_hash  | 
| 
85
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
86
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 Takes over the given hash to be the new contents of the Scope::Hash.  | 
| 
87
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 Usage example:  | 
| 
88
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
89
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     $scope->adopt_hash({ foo => 42 });  | 
| 
90
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
91
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 The scope uses exactly the hash passed, not a clone of it.  If this is not  | 
| 
92
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 applicable to a subclass, that subclass should override it as C<...> or an  | 
| 
93
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 express C.  | 
| 
94
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
95
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =cut  | 
| 
96
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
97
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub adopt_hash {  | 
| 
98
 | 
5
 | 
  
100
  
 | 
 
 | 
  
5
  
 | 
  
1
  
 | 
2626
 | 
     my $self = shift or croak 'Need an instance';  | 
| 
99
 | 
4
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
109
 | 
     my $hrNew = shift or croak 'Need a hash to adopt';  | 
| 
100
 | 
3
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
195
 | 
     croak 'Cannot adopt a non-hash' unless ref $hrNew eq 'HASH';  | 
| 
101
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
26
 | 
     $self->_content($hrNew);  | 
| 
102
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
8
 | 
     return $self;  | 
| 
103
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 } #adopt_hash()  | 
| 
104
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
105
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =head2 _names_here  | 
| 
106
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
107
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 Populates a L with the names of the items stored in this Scope,  | 
| 
108
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 but B any outer Scope.  Called as:  | 
| 
109
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
110
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     $scope->_names_here($retval[, $set]);  | 
| 
111
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
112
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 No return value.  | 
| 
113
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
114
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =cut  | 
| 
115
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
116
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub _names_here {  | 
| 
117
 | 
520
 | 
 
 | 
 
 | 
  
520
  
 | 
 
 | 
1797
 | 
     my ($self, %args) = getparameters('self', [qw(retval ; set)], @_);  | 
| 
118
 | 
520
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
66545
 | 
     _set0 $args{set} or croak 'I only support set 0';  | 
| 
119
 | 
520
 | 
 
 | 
 
 | 
 
 | 
 
 | 
1130
 | 
     $args{retval}->insert(keys %{$self->_content});  | 
| 
 
 | 
520
 | 
 
 | 
 
 | 
 
 | 
 
 | 
11460
 | 
    | 
| 
120
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 } #_names_here()  | 
| 
121
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
122
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =head2 _find_here  | 
| 
123
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
124
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 Looks for a given item in this scope, but B any outer scope.  Called as:  | 
| 
125
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
126
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     $scope->_find_here($name[, $set])  | 
| 
127
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
128
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 Returns the value, or C if not found.  | 
| 
129
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
130
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 =cut  | 
| 
131
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
132
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub _find_here {  | 
| 
133
 | 
532
 | 
 
 | 
 
 | 
  
532
  
 | 
 
 | 
2046
 | 
     my ($self, %args) = getparameters('self', [qw(name ; set)], @_);  | 
| 
134
 | 
532
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
30994
 | 
     _set0 $args{set} or croak 'I only support set 0';  | 
| 
135
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
136
 | 
532
 | 
 
 | 
 
 | 
 
 | 
 
 | 
10775
 | 
     my $val = $self->_content->{$args{name}};  | 
| 
137
 | 
532
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
3539
 | 
     return undef unless defined $val;  | 
| 
138
 | 
328
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
1362
 | 
     return ($args{set} eq '*') ? { 0 => $val } : $val;  | 
| 
139
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 } #_find_here()  | 
| 
140
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
141
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 1;  | 
| 
142
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 __END__  |