line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package AsciiDB::TagRecord; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Copyright (c) 1997-2001 Jose A. Rodriguez. All rights reserved. |
4
|
|
|
|
|
|
|
# This program is free software; you can redistribute it and/or modify it |
5
|
|
|
|
|
|
|
# under the same terms as Perl itself. |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
require Tie::Hash; |
8
|
|
|
|
|
|
|
@ISA = (Tie::Hash); |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
$VERSION = '1.06'; |
11
|
|
|
|
|
|
|
|
12
|
6
|
|
|
6
|
|
34
|
use Carp; |
|
6
|
|
|
|
|
8
|
|
|
6
|
|
|
|
|
7305
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub TIEHASH { |
15
|
109
|
|
|
109
|
|
187
|
my $class = shift; |
16
|
109
|
|
|
|
|
320
|
my %params = @_; |
17
|
|
|
|
|
|
|
|
18
|
109
|
|
|
|
|
164
|
my $self = {}; |
19
|
109
|
|
|
|
|
216
|
$self->{_FILENAME} = $params{FILENAME}; |
20
|
109
|
|
|
|
|
156
|
$self->{_SCHEMA} = $params{SCHEMA}; |
21
|
109
|
|
|
|
|
148
|
$self->{_READONLY} = $params{READONLY}; |
22
|
109
|
|
|
|
|
151
|
$self->{_FILEMODE} = $params{FILEMODE}; |
23
|
109
|
|
|
|
|
158
|
$self->{_LOCK} = $params{LOCK}; |
24
|
|
|
|
|
|
|
|
25
|
109
|
|
|
|
|
437
|
bless $self, $class; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub FETCH { |
29
|
117
|
|
|
117
|
|
184
|
my ($self, $key) = @_; |
30
|
|
|
|
|
|
|
|
31
|
117
|
100
|
|
|
|
320
|
$self->load() unless exists $self->{_LOADED}; |
32
|
|
|
|
|
|
|
|
33
|
117
|
|
|
|
|
487
|
return $self->{$key}; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub STORE { |
37
|
62
|
|
|
62
|
|
101
|
my ($self, $key, $value) = @_; |
38
|
|
|
|
|
|
|
|
39
|
62
|
100
|
|
|
|
143
|
return if $self->{_READONLY}; |
40
|
|
|
|
|
|
|
|
41
|
61
|
50
|
66
|
|
|
947
|
$self->load() unless |
42
|
|
|
|
|
|
|
exists ($self->{_LOADED}) or (! -f $self->{_FILENAME}); |
43
|
|
|
|
|
|
|
|
44
|
61
|
|
|
|
|
133
|
$self->{$key} = $value; |
45
|
61
|
|
|
|
|
73
|
$self->{_LOADED} = 1; |
46
|
61
|
|
|
|
|
214
|
$self->{_UPDATED} = 1; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub FIRSTKEY { |
50
|
1
|
|
|
1
|
|
2
|
my $self = shift; |
51
|
|
|
|
|
|
|
|
52
|
1
|
|
|
|
|
3
|
my %schema = %{$self->{_SCHEMA}}; |
|
1
|
|
|
|
|
5
|
|
53
|
1
|
|
|
|
|
2
|
my @iterator = @{$schema{ORDER}}; |
|
1
|
|
|
|
|
4
|
|
54
|
1
|
|
|
|
|
4
|
$self->{_ITERATOR} = \@iterator; |
55
|
|
|
|
|
|
|
|
56
|
1
|
|
|
|
|
2
|
shift @{$self->{_ITERATOR}}; |
|
1
|
|
|
|
|
6
|
|
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub NEXTKEY { |
60
|
4
|
|
|
4
|
|
5
|
my $self = shift; |
61
|
|
|
|
|
|
|
|
62
|
4
|
|
|
|
|
5
|
shift @{$self->{_ITERATOR}}; |
|
4
|
|
|
|
|
12
|
|
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub DELETE { |
66
|
0
|
|
|
0
|
|
0
|
my ($self, $key) = @_; |
67
|
|
|
|
|
|
|
|
68
|
0
|
0
|
|
|
|
0
|
$self->load() unless exists $self->{_LOADED}; |
69
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
0
|
delete $self->{$key}; |
71
|
0
|
|
|
|
|
0
|
$self->{_UPDATED} = 1; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub DESTROY { |
75
|
101
|
|
|
101
|
|
121
|
my $self = shift; |
76
|
|
|
|
|
|
|
|
77
|
101
|
|
|
|
|
156
|
$self->sync(); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub load { |
81
|
54
|
|
|
54
|
0
|
65
|
my $self = shift; |
82
|
|
|
|
|
|
|
|
83
|
54
|
50
|
|
|
|
1750
|
open (RECORD, $self->{_FILENAME}) |
84
|
|
|
|
|
|
|
or croak "Can't open $self->{_FILENAME} record"; |
85
|
|
|
|
|
|
|
|
86
|
54
|
50
|
|
|
|
147
|
flock(RECORD, 1) if $self->{_LOCK}; # Get shared lock |
87
|
|
|
|
|
|
|
|
88
|
54
|
|
|
|
|
79
|
my $fieldName = ''; |
89
|
54
|
|
|
|
|
54
|
my $line; |
90
|
54
|
|
|
|
|
602
|
while (defined ($line = )) { |
91
|
216
|
50
|
|
|
|
932
|
if ($line =~ /^\[(.+)\]:\s?(.*)$/) { |
92
|
216
|
|
|
|
|
611
|
$self->{$fieldName = $1} = $2; |
93
|
216
|
|
|
|
|
880
|
next; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
0
|
chomp $line; |
97
|
0
|
|
|
|
|
0
|
$self->{$fieldName} .= "\n$line"; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
54
|
|
|
|
|
496
|
close (RECORD); # This close unlocks the file |
101
|
|
|
|
|
|
|
|
102
|
54
|
|
|
|
|
106
|
$self->{_LOADED} = 1; |
103
|
54
|
|
|
|
|
112
|
delete $self->{_UPDATED}; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub deleteRecord { |
107
|
11
|
|
|
11
|
0
|
10
|
my $self = shift; |
108
|
|
|
|
|
|
|
|
109
|
11
|
|
|
|
|
13
|
$self->{_LOADED} = 1; |
110
|
11
|
|
|
|
|
60
|
$self->{_UPDATED} = 0; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub sync { |
114
|
103
|
|
|
103
|
0
|
104
|
my $self = shift; |
115
|
|
|
|
|
|
|
|
116
|
103
|
100
|
66
|
|
|
571
|
return if $self->{_READONLY} || ! $self->{_UPDATED}; |
117
|
|
|
|
|
|
|
|
118
|
52
|
50
|
|
|
|
2693
|
open (RECORD, "> $$self{_FILENAME}") |
119
|
|
|
|
|
|
|
or croak "Can't create $$self{_FILENAME} record"; |
120
|
|
|
|
|
|
|
|
121
|
52
|
50
|
|
|
|
127
|
flock(RECORD, 2) if $self->{_LOCK}; # Get shared lock |
122
|
|
|
|
|
|
|
|
123
|
52
|
|
|
|
|
47
|
my %schema = %{$self->{_SCHEMA}}; |
|
52
|
|
|
|
|
155
|
|
124
|
52
|
|
|
|
|
64
|
my $fieldName; |
125
|
52
|
|
|
|
|
46
|
foreach $fieldName (@{$schema{ORDER}}) { |
|
52
|
|
|
|
|
79
|
|
126
|
208
|
100
|
|
|
|
653
|
print RECORD ("[$fieldName]: ", |
127
|
|
|
|
|
|
|
defined($self->{$fieldName}) ? |
128
|
|
|
|
|
|
|
$self->{$fieldName} : '', "\n"); |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
52
|
|
|
|
|
1662
|
close (RECORD); # This close unlocks the file |
132
|
|
|
|
|
|
|
|
133
|
52
|
50
|
|
|
|
118
|
if (defined $self->{_FILEMODE}) { |
134
|
0
|
0
|
|
|
|
0
|
chmod ($self->{_FILEMODE}, $self->{_FILENAME}) |
135
|
|
|
|
|
|
|
or croak "Can't chmod $$self{_FILENAME}"; |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
52
|
|
|
|
|
336
|
delete $self->{_UPDATED}; |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
1; |