| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
#!/usr/bin/perl |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Goo::WebDBLite; |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
############################################################################### |
|
6
|
|
|
|
|
|
|
# Turbo10 |
|
7
|
|
|
|
|
|
|
# |
|
8
|
|
|
|
|
|
|
# Copyright Nigel Hamilton 2003 |
|
9
|
|
|
|
|
|
|
# All rights reserved |
|
10
|
|
|
|
|
|
|
# |
|
11
|
|
|
|
|
|
|
# Author: Nigel Hamilton |
|
12
|
|
|
|
|
|
|
# Filename: Goo::WebDBLite.pm |
|
13
|
|
|
|
|
|
|
# Description: This provides a Lite interface to the Data to reduce RAM |
|
14
|
|
|
|
|
|
|
# requirements. Each Apache child was 100Meg - too big. |
|
15
|
|
|
|
|
|
|
# Many of the templates stored in the WebDB are redundant |
|
16
|
|
|
|
|
|
|
# so in the interests of RAM conservation changed to WebDBLite |
|
17
|
|
|
|
|
|
|
# This does a 'lazy load' of pages into a per Apache child |
|
18
|
|
|
|
|
|
|
# RAM cache. |
|
19
|
|
|
|
|
|
|
# |
|
20
|
|
|
|
|
|
|
# Date Change |
|
21
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------- |
|
22
|
|
|
|
|
|
|
# 25/02/2002 Version 1 |
|
23
|
|
|
|
|
|
|
# 24/06/2003 Consuming too much RAM need to reduce the RAM requirements |
|
24
|
|
|
|
|
|
|
# for mod_perl - turned out most of the RAM was consumed by |
|
25
|
|
|
|
|
|
|
# Rackspace's Apache configuration which included: mod_php, |
|
26
|
|
|
|
|
|
|
# mod_perl etc. |
|
27
|
|
|
|
|
|
|
# 02/02/2005 Added whitespace compression to compress objects in RAM and |
|
28
|
|
|
|
|
|
|
# for transmission across the Net! Improved parsing of WebDB data |
|
29
|
|
|
|
|
|
|
# Don't compress the files on disk for readability but *do* |
|
30
|
|
|
|
|
|
|
# 05/02/2005 Added getTemplate for simpler access to "bodytext" templates |
|
31
|
|
|
|
|
|
|
# 22/06/2005 Moving to Goo2! Added type_locations as a bridge before the |
|
32
|
|
|
|
|
|
|
# full Goo changes kick in! |
|
33
|
|
|
|
|
|
|
# |
|
34
|
|
|
|
|
|
|
############################################################################## |
|
35
|
|
|
|
|
|
|
|
|
36
|
1
|
|
|
1
|
|
14116
|
use strict; |
|
|
1
|
|
|
|
|
4
|
|
|
|
1
|
|
|
|
|
42
|
|
|
37
|
|
|
|
|
|
|
|
|
38
|
1
|
|
|
1
|
|
7
|
use Goo::Object; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
24
|
|
|
39
|
1
|
|
|
1
|
|
6
|
use Goo::FileUtilities; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
23
|
|
|
40
|
1
|
|
|
1
|
|
5
|
use Goo::CompressWhitespace; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
29
|
|
|
41
|
|
|
|
|
|
|
|
|
42
|
1
|
|
|
1
|
|
6
|
use base qw(Goo::Object); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
812
|
|
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# master data directory |
|
45
|
|
|
|
|
|
|
my $datadirectory = "/home/search/web/webdb/"; |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# master database hash |
|
48
|
|
|
|
|
|
|
our $db = {}; |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
my $goobase = "$ENV{HOME}/.goo"; |
|
51
|
|
|
|
|
|
|
my $type_locations = { formtemplate => "$goobase/things/frm", |
|
52
|
|
|
|
|
|
|
page => "$goobase/things/page", |
|
53
|
|
|
|
|
|
|
email => "$goobase/things/email", |
|
54
|
|
|
|
|
|
|
emailtemplate => "$goobase/things/email", |
|
55
|
|
|
|
|
|
|
settings => "$goobase/things/settings", |
|
56
|
|
|
|
|
|
|
template => "$goobase/things/tpl" }; |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
############################################################################## |
|
60
|
|
|
|
|
|
|
# |
|
61
|
|
|
|
|
|
|
# get_value - return a value - polymorphically |
|
62
|
|
|
|
|
|
|
# |
|
63
|
|
|
|
|
|
|
############################################################################## |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub get_value { |
|
66
|
|
|
|
|
|
|
|
|
67
|
0
|
|
|
0
|
1
|
|
my ($type, $id, $field) = @_; |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# all ids must be in lowercase |
|
70
|
0
|
|
|
|
|
|
$type = lc($type); |
|
71
|
0
|
|
|
|
|
|
$id = lc($id); |
|
72
|
0
|
|
|
|
|
|
$field = lc($field); |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# special exception - HTML pages need a new suffix |
|
75
|
0
|
0
|
|
|
|
|
if ($id =~ /html$/) { |
|
76
|
0
|
|
|
|
|
|
$id =~ s/html/page/g; |
|
77
|
|
|
|
|
|
|
} |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
# special exception - yuck! |
|
80
|
0
|
0
|
|
|
|
|
if ($id =~ /general$/) { |
|
81
|
0
|
|
|
|
|
|
$id = "general.settings"; |
|
82
|
|
|
|
|
|
|
} |
|
83
|
|
|
|
|
|
|
|
|
84
|
0
|
0
|
|
|
|
|
if (not exists $db->{$type}->{$id}) { |
|
85
|
0
|
|
|
|
|
|
load_object($type, $id); |
|
86
|
|
|
|
|
|
|
} |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
# accessing an Object attribute |
|
89
|
0
|
0
|
|
|
|
|
if ($field ne "") { |
|
90
|
0
|
|
|
|
|
|
return $db->{$type}->{$id}->{$field}; |
|
91
|
|
|
|
|
|
|
} |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
# accessing an Object |
|
94
|
0
|
|
|
|
|
|
return $db->{$type}->{$id}; |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
} |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
############################################################################## |
|
100
|
|
|
|
|
|
|
# |
|
101
|
|
|
|
|
|
|
# get_template - simpler access |
|
102
|
|
|
|
|
|
|
# |
|
103
|
|
|
|
|
|
|
############################################################################## |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub get_template { |
|
106
|
|
|
|
|
|
|
|
|
107
|
0
|
|
|
0
|
1
|
|
my ($template_name) = @_; |
|
108
|
|
|
|
|
|
|
|
|
109
|
0
|
|
|
|
|
|
return get_value("template", $template_name, "bodytext"); |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
} |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
############################################################################## |
|
116
|
|
|
|
|
|
|
# |
|
117
|
|
|
|
|
|
|
# load_object - load the data file from disk - this will take some memory |
|
118
|
|
|
|
|
|
|
# but should be no problem |
|
119
|
|
|
|
|
|
|
# |
|
120
|
|
|
|
|
|
|
############################################################################## |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub load_object { |
|
123
|
|
|
|
|
|
|
|
|
124
|
0
|
|
|
0
|
1
|
|
my ($type, $id) = @_; |
|
125
|
|
|
|
|
|
|
|
|
126
|
0
|
|
|
|
|
|
my $location = $type_locations->{$type}; |
|
127
|
|
|
|
|
|
|
|
|
128
|
0
|
0
|
|
|
|
|
unless ($location) { |
|
129
|
0
|
|
|
|
|
|
die("No location found for $type [$id]"); |
|
130
|
|
|
|
|
|
|
} |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
# special exception - HTML pages need a new suffix |
|
133
|
0
|
0
|
|
|
|
|
if ($id =~ /html$/) { |
|
134
|
0
|
|
|
|
|
|
$id =~ s/html/page/g; |
|
135
|
|
|
|
|
|
|
} |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
# another special exception |
|
138
|
0
|
0
|
|
|
|
|
if ($id =~ /general$/) { |
|
139
|
0
|
|
|
|
|
|
$id = "general.settings"; |
|
140
|
|
|
|
|
|
|
} |
|
141
|
|
|
|
|
|
|
|
|
142
|
0
|
|
|
|
|
|
my $datafile = $location."/".$id; |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
# slurp mode |
|
145
|
0
|
|
|
|
|
|
my $data = Goo::FileUtilities::get_file_as_string($datafile); |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
# parse here! |
|
148
|
0
|
|
|
|
|
|
while ($data =~ m|<([^>]*)>(.*?)</\1>|gs) { |
|
149
|
|
|
|
|
|
|
|
|
150
|
0
|
|
|
|
|
|
my $field = $1; |
|
151
|
0
|
|
|
|
|
|
my $value = $2; |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
# compress all objects except for emailtemplates |
|
154
|
0
|
0
|
0
|
|
|
|
if (($value =~ /<[^>]*>/) && ($type ne "emailtemplate")) { |
|
155
|
|
|
|
|
|
|
# compress the object, save RAM and gain speed - strip leading whitespace |
|
156
|
0
|
|
|
|
|
|
Goo::CompressWhitespace::compress_html(\$value); |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
} |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
# print "$value"; |
|
161
|
|
|
|
|
|
|
# a hash of a hash of a hash - wow |
|
162
|
0
|
|
|
|
|
|
$db->{$type}->{$id}->{$field} = $value; |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
} |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
} |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
1; |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
__END__ |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=head1 NAME |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
Goo::WebDBLite - This provides a Lite interface to XMLish Things |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
use Goo::WebDBLite; |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=head1 METHODS |
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=over |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=item get_value |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
return a value - polymorphically |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=item get_template |
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
return a text template |
|
196
|
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=item load_object |
|
198
|
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
load the data file from disk - this will take some memory |
|
200
|
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=back |
|
202
|
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=head1 AUTHOR |
|
204
|
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
Nigel Hamilton <nigel@trexy.com> |
|
206
|
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
208
|
|
|
|
|
|
|
|