line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
### |
3
|
|
|
|
|
|
|
### Copyright 2002-2003 University of Illinois Board of Trustees |
4
|
|
|
|
|
|
|
### Copyright 2002-2003 Mark D. Roth |
5
|
|
|
|
|
|
|
### All rights reserved. |
6
|
|
|
|
|
|
|
### |
7
|
|
|
|
|
|
|
### Config::Objective::Hash - hash data type for Config::Objective |
8
|
|
|
|
|
|
|
### |
9
|
|
|
|
|
|
|
### Mark D. Roth |
10
|
|
|
|
|
|
|
### Campus Information Technologies and Educational Services |
11
|
|
|
|
|
|
|
### University of Illinois at Urbana-Champaign |
12
|
|
|
|
|
|
|
### |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
package Config::Objective::Hash; |
16
|
|
|
|
|
|
|
|
17
|
1
|
|
|
1
|
|
472
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
23
|
|
18
|
|
|
|
|
|
|
|
19
|
1
|
|
|
1
|
|
5
|
use Config::Objective::DataType; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
692
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
our @ISA = qw(Config::Objective::DataType); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
############################################################################### |
25
|
|
|
|
|
|
|
### default method is insert() |
26
|
|
|
|
|
|
|
############################################################################### |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub default |
29
|
|
|
|
|
|
|
{ |
30
|
9
|
|
|
9
|
1
|
16
|
my ($self, $value) = @_; |
31
|
|
|
|
|
|
|
|
32
|
9
|
|
|
|
|
26
|
$self->insert($value); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
############################################################################### |
37
|
|
|
|
|
|
|
### unset method |
38
|
|
|
|
|
|
|
############################################################################### |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub unset |
41
|
|
|
|
|
|
|
{ |
42
|
5
|
|
|
5
|
1
|
8
|
my ($self) = @_; |
43
|
|
|
|
|
|
|
|
44
|
5
|
|
|
|
|
15
|
$self->{'value'} = {}; |
45
|
5
|
|
|
|
|
11
|
return 1; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
############################################################################### |
50
|
|
|
|
|
|
|
### set method |
51
|
|
|
|
|
|
|
############################################################################### |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub set |
54
|
|
|
|
|
|
|
{ |
55
|
0
|
|
|
0
|
1
|
0
|
my ($self, $value) = @_; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
# print "==> Hash::set($value)\n"; |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
0
|
$self->unset(); |
60
|
0
|
|
|
|
|
0
|
return $self->insert($value); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
############################################################################### |
65
|
|
|
|
|
|
|
### insert method |
66
|
|
|
|
|
|
|
############################################################################### |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub insert |
69
|
|
|
|
|
|
|
{ |
70
|
9
|
|
|
9
|
1
|
14
|
my ($self, $value) = @_; |
71
|
9
|
|
|
|
|
11
|
my ($key1, $key2); |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# print "==> Hash::insert($value)\n"; |
74
|
|
|
|
|
|
|
|
75
|
9
|
50
|
|
|
|
28
|
die "insert: method requires hash argument\n" |
76
|
|
|
|
|
|
|
if (ref($value) ne 'HASH'); |
77
|
|
|
|
|
|
|
|
78
|
9
|
50
|
|
|
|
29
|
$self->{'value'} = {} |
79
|
|
|
|
|
|
|
if (!defined($self->{'value'})); |
80
|
|
|
|
|
|
|
|
81
|
9
|
|
|
|
|
30
|
foreach $key1 (keys %$value) |
82
|
|
|
|
|
|
|
{ |
83
|
18
|
50
|
|
|
|
44
|
print "\t'$key1' => '$value->{$key1}'\n" |
84
|
|
|
|
|
|
|
if ($self->{'debug'}); |
85
|
|
|
|
|
|
|
|
86
|
18
|
50
|
33
|
|
|
50
|
die "key must be an absolute path\n" |
87
|
|
|
|
|
|
|
if ($self->{'key_abspath'} |
88
|
|
|
|
|
|
|
&& $key1 !~ m|^/|); |
89
|
|
|
|
|
|
|
|
90
|
18
|
100
|
|
|
|
43
|
if (!defined($value->{$key1})) |
91
|
|
|
|
|
|
|
{ |
92
|
3
|
50
|
|
|
|
9
|
die "hash value missing\n" |
93
|
|
|
|
|
|
|
if (!$self->{'value_optional'}); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
else |
96
|
|
|
|
|
|
|
{ |
97
|
15
|
50
|
66
|
|
|
55
|
die "hash value is not a $self->{'value_type'}\n" |
98
|
|
|
|
|
|
|
if (defined($self->{'value_type'}) |
99
|
|
|
|
|
|
|
&& $self->{'value_type'} ne ref($value->{$key1})); |
100
|
|
|
|
|
|
|
|
101
|
15
|
50
|
33
|
|
|
44
|
die "value must be an absolute path\n" |
102
|
|
|
|
|
|
|
if ($self->{'value_abspath'} |
103
|
|
|
|
|
|
|
&& $value->{$key1} !~ m|^/|); |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
18
|
100
|
|
|
|
46
|
if (exists($self->{'value'}->{$key1})) |
107
|
|
|
|
|
|
|
{ |
108
|
|
|
|
|
|
|
# print "key1='$key1'\n"; |
109
|
2
|
100
|
|
|
|
12
|
if (ref($self->{'value'}->{$key1}) eq 'HASH') |
|
|
50
|
|
|
|
|
|
110
|
|
|
|
|
|
|
{ |
111
|
|
|
|
|
|
|
# print "key1={" . join(',', sort keys %{$self->{'value'}->{$key1}}) . "}\n"; |
112
|
1
|
|
|
|
|
2
|
foreach $key2 (keys %{$value->{$key1}}) |
|
1
|
|
|
|
|
4
|
|
113
|
|
|
|
|
|
|
{ |
114
|
|
|
|
|
|
|
# print "\tkey2='$key2'\n"; |
115
|
1
|
|
|
|
|
5
|
$self->{'value'}->{$key1}->{$key2} = $value->{$key1}->{$key2}; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
# print "'$key1' => { " . join(', ', sort keys %{$self->{'value'}->{$key1}}) . " }\n"; |
119
|
1
|
|
|
|
|
4
|
next; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
elsif (ref($self->{'value'}->{$key1}) eq 'ARRAY') |
122
|
|
|
|
|
|
|
{ |
123
|
1
|
|
|
|
|
2
|
push(@{$self->{'value'}->{$key1}}, @{$value->{$key1}}); |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
4
|
|
124
|
1
|
|
|
|
|
3
|
next; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
### overwrite the existing entry |
129
|
|
|
|
|
|
|
### or create a new one |
130
|
16
|
50
|
|
|
|
34
|
print "OVERRIDE: $value->{$key1}\n" |
131
|
|
|
|
|
|
|
if ($self->{'debug'}); |
132
|
16
|
|
|
|
|
46
|
$self->{'value'}->{$key1} = $value->{$key1}; |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
9
|
|
|
|
|
35
|
return 1; |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
############################################################################### |
140
|
|
|
|
|
|
|
### exists method |
141
|
|
|
|
|
|
|
############################################################################### |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
sub exists |
144
|
|
|
|
|
|
|
{ |
145
|
0
|
|
|
0
|
1
|
0
|
my ($self, $value) = @_; |
146
|
|
|
|
|
|
|
|
147
|
0
|
0
|
|
|
|
0
|
return (exists($self->{'value'}->{$value}) ? 1 : 0); |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
############################################################################### |
152
|
|
|
|
|
|
|
### find method |
153
|
|
|
|
|
|
|
############################################################################### |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
sub find |
156
|
|
|
|
|
|
|
{ |
157
|
0
|
|
|
0
|
1
|
0
|
my ($self, $value) = @_; |
158
|
|
|
|
|
|
|
|
159
|
0
|
0
|
|
|
|
0
|
return (exists($self->{value}->{$value}) |
160
|
|
|
|
|
|
|
? $self->{value}->{$value} |
161
|
|
|
|
|
|
|
: undef); |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
############################################################################### |
166
|
|
|
|
|
|
|
### delete method |
167
|
|
|
|
|
|
|
############################################################################### |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
sub delete |
170
|
|
|
|
|
|
|
{ |
171
|
3
|
|
|
3
|
1
|
6
|
my ($self, $value) = @_; |
172
|
3
|
|
|
|
|
4
|
my ($val); |
173
|
|
|
|
|
|
|
|
174
|
3
|
|
|
|
|
21
|
$value = $self->_scalar_or_list($value); |
175
|
3
|
|
|
|
|
8
|
foreach $val (@$value) |
176
|
|
|
|
|
|
|
{ |
177
|
4
|
|
|
|
|
14
|
delete $self->{'value'}->{$val}; |
178
|
|
|
|
|
|
|
} |
179
|
|
|
|
|
|
|
|
180
|
3
|
|
|
|
|
10
|
return 1; |
181
|
|
|
|
|
|
|
} |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
############################################################################### |
185
|
|
|
|
|
|
|
### cleanup and documentation |
186
|
|
|
|
|
|
|
############################################################################### |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
1; |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
__END__ |