Line # Revision Author
1 3 ahitrov@rambler.ru package Contenido::State;
2
3 # ----------------------------------------------------------------------------
4 # Contenido::State - �����, ����������� ������� ��������� �������.
5 # ������ ����� ������ ��������� ��� ������ Apache-������� � �����������
6 # ������� �� handler.pl ��� startup.pl. ���������� ������ (����, URL,
7 # ������ � �.�.) ���������� � startup.pl � ������� ������������ ���������
8 # sandbox (@@PORT@@).
9 # ----------------------------------------------------------------------------
10
11 use strict;
12 use vars qw($VERSION $AUTOLOAD);
13 $VERSION = '4.2';
14
15 use Utils;
16 use Contenido::Globals;
17
18 use @MEMCACHED_BACKEND@;
19
20 sub new
21 {
22 my ($proto) = shift;
23 my $class = ref($proto) || $proto;
24 my $self = {};
25 bless($self, $class);
26
27 $self->{project} = '@PROJECT@';
28 $self->{project_version} = '@PROJECT_VERSION@';
29 $self->{core_version} = '@CORE_VERSION@';
30
31 $self->{db_type} = lc('@DB_TYPE@') || 'single';
32 $self->{db_keepalive} = (lc('@PERSISTENT_CONN@') eq 'no') ? 0:1;
33 $self->{db_host} = (($self->{db_type} eq 'remote') and '@BASE_HOST@') ? lc('@BASE_HOST@') : 'localhost';
34 $self->{db_name} = '@PGSQL_BASE@';
35 $self->{db_user} = '@BASE_USER@';
36 $self->{db_password} = '@BASE_PASSWD@';
37 $self->{db_port} = '@PGSQL_PORT@';
38 $self->{db_prepare} = lc('@PGSQL_REAL_PREPARE@') eq 'yes' ? 1 : 0;
39 $self->{db_enable_utf8} = lc('@PGSQL_ENABLE_UTF@') eq 'yes' ? 1 : 0;
40 $self->{db_client_encoding} = '@PGSQL_CLIENT_ENCODING@';
41
42 $self->{db_encode_data} = '@PGSQL_ENCODE_DATA@';
43 $self->{db_decode_data} = '@PGSQL_DECODE_DATA@' || 'utf-8';
44
45 $self->{master_db_host} = (($self->{db_type} eq 'remote') and '@MASTER_BASE_HOST@') ? lc('@MASTER_BASE_HOST@') : 'localhost';
46 $self->{master_db_name} = '@MASTER_BASE_NAME@';
47 $self->{master_db_user} = '@MASTER_BASE_USER@';
48 $self->{master_db_password} = '@MASTER_BASE_PASSWD@';
49 $self->{master_db_port} = '@MASTER_BASE_PORT@';
50
51 $self->{session_dir} = '@SESSIONS@';
52 $self->{session_directory} = '@SESSIONS@';
53
54 $self->{crosslinks_dir} = '@CROSSLINKS@';
55 $self->{crosslinks_directory} = '@CROSSLINKS@';
56
57 $self->{httpd_port} = '@HTTPD_PORT@';
58 $self->{httpd_server} = '@HTTPD_SERVER@';
59 $self->{httpd_root} = 'http://'.$self->{httpd_server}.'/';
60
61 $self->{plugins} = '@PLUGINS@';
62
63 $self->{prefix} = '@PREFIX@';
64
65 $self->{images_directory} = '@IMAGES@';
66 $self->{images_dir} = '@IMAGES@';
67
68 $self->{proxy_image_location} = '@PROXY_IMAGE_LOCATION@';
69 $self->{proxy_image_secret} = '@PROXY_IMAGE_SECRET@';
70
71
72 $self->{binary_directory} = '@BINARY@';
73 $self->{binary_dir} = '@BINARY@';
74
75 {
76 my $files_dir = '@FILES@';
77 $self->{files_dir} = [split /\s+/ms, $files_dir];
78 }
79
80 364 ahitrov $self->{composite_binary} = '@COMPOSITE@';
81 3 ahitrov@rambler.ru $self->{convert_binary} = '@CONVERT@';
82 204 ahitrov $self->{file_web_storage} = lc('@FILE_WEB_STORAGE@');
83 3 ahitrov@rambler.ru
84 $self->{core_src} = '@CORE_SRC@';
85 $self->{plug_src} = '@PLUG_SRC@';
86 $self->{proj_src} = '@PROJ_SRC@';
87
88 $self->{log_dir} = '@PROJECT_LOG@';
89 $self->{run_dir} = '@PROJECT_RUN@';
90 $self->{tmp_dir} = '@PROJECT_TMP@';
91 $self->{usr_dir} = '@PROJECT_USR@';
92
93 $self->{var_dir} = '@PROJECT_VAR@';
94 $self->{data_dir} = $self->{var_dir};
95 $self->{data_directory} = $self->{var_dir};
96
97 $self->{preview} = '@PREVIEW@';
98 $self->{mason_comp} = '@MASON_COMP@';
99
100 $self->{auth_cookie} = '@AUTH_COOKIE@';
101
102 $self->{is_dev_server} = lc('@DEVELOPMENT@') eq 'yes';
103 $self->{development} = lc('@DEVELOPMENT@') eq 'yes';
104
105 $self->{contenido_version} = '@CONTENIDO_VERSION@' + 0;
106 $self->{version} = $self->{contenido_version};
107
108 $self->{__debug__} = (lc('@DEBUG@') eq 'yes');
109 $self->{__debug_format__} = '@DEBUG_FORMAT@';
110 $self->{__debug_stack_trace__} = lc('@DEBUG_STACK_TRACE@') eq 'yes';
111 $self->{__debug_min_level__} = '@DEBUG_MIN_LEVEL@';
112 $self->{__debug_max_level__} = '@DEBUG_MAX_LEVEL@';
113 $self->{__sql_debug__} = lc('@DEBUG_SQL@') eq 'yes';
114
115 $self->{project_name} = '@PROJECT_NAME@';
116 $self->{multidomain} = lc('@MULTIDOMAIN@') eq 'yes';
117 $self->{stage} = 'REAL';
118
119 $state->{readonly} = (lc('@READONLY@') eq 'yes');
120
121 $self->{store_method} = lc('@STORE_METHOD@');
122 $Contenido::Globals::store_method = $self->{store_method};
123
124 $self->{cascade} = (lc('@CASCADE@') eq 'yes');
125
126 $self->{locale} = '@LOCALE@';
127
128 # ���������������� ��������� memcached
129 $self->{memcached_backend} = '@MEMCACHED_BACKEND@';
130 $self->{memcached_enable} = lc( '@MEMCACHED_ENABLE@' ) eq 'yes' ? 1 : 0;
131 $self->{memcached_select_timeout} = '@MEMCACHED_SELECT_TIMEOUT@' || 0.2;
132 $self->{memcached_servers} = [ split(/\s+/, '@MEMCACHED_SERVERS@') ];
133 $self->{memcached_enable_compress} = lc( '@MEMCACHED_ENABLE_COMPRESS@' ) eq 'yes' ? 1 : 0;
134 $self->{memcached_delayed} = lc('@MEMCACHED_DELAYED@') eq 'yes' ? 1 : 0;
135 $self->{memcached_set_mode} = lc('@MEMCACHED_SET_MODE@') eq 'add' ? 'add' : 'set';
136 $self->{memcached_namespace} = lc( $self->{'project'} ).'|';
137
138 $self->{memcached_object_expire} = undef;
139
140 $self->{options_expire} = '@OPTIONS_EXPIRE@';
141
142 $self->{preamble_handler} = '@PREAMBLE_HANDLER@';
143 $self->{preamble_handler_path} = '@PREAMBLE_HANDLER_PATH@';
144
145 $self->_refresh_();
146 $self->_init_();
147
148 my @plugins = split(/\s+/, $self->plugins());
149 for my $plugin ($self->{project}, @plugins) {
150 $self->{lc($plugin)} = {};
151 $self->{attributes}->{lc($plugin)} = 'SCALAR';
152
153 my $class = $plugin.'::State';
154 eval ("use $class");
155
156 if ( $@ ) {
157 warn "Contenido Error: �� ���� ���������� ��������� ������� $plugin ($class) �� ������� '$@'.\n";
158 } else {
159 warn "Contenido Init: �������� ����� $class ��� ������� $plugin.\n" if ($self->debug());
160 eval {
161 $self->{lc($plugin)} = $class->new();
162 };
163 if ( $@ ) {
164 warn "Contenido Error: �� ���� ��������� ������������� ��������� ������� $plugin ($class) �� ������� '$@'.\n";
165 }
166 }
167 }
168
169
170
171
172 return $self;
173 }
174
175
176
177 sub _refresh_
178 {
179 my $self = shift;
180 $self->{debug} = $self->{__debug__};
181 #���������� $DEBUG � $DEBUG_SQL � ���������� ��������!!!
182 $DEBUG_SQL = $self->{__sql_debug__};
183 $DEBUG = $self->{__debug__};
184 }
185
186
187 # ----------------------------------------------------------------------------
188 # ����� ���������� �� �������...
189 # ----------------------------------------------------------------------------
190 sub info
191 {
192 my $self = shift;
193 return undef unless ref($self);
194
195 $log->info("������ Contenido::State �������� ���������� �����������:");
196 foreach my $attribute (sort (keys( %{ $self->{attributes} } )))
197 {
198 my $la = length($attribute);
199 warn "\t".$attribute.("\t" x (2-int($la/8))).": ".$self->{$attribute}."\n";
200 }
201
202 my @plugins = split(/\s+/, $self->plugins());
203 for my $plugin ($self->{project}, @plugins) {
204 if (ref($self->{lc($plugin)})) {
205 eval {
206 $self->{lc($plugin)}->info();
207 };
208 }
209 }
210 }
211
212
213
214 # ----------------------------------------------------------------------------
215 # �������������.
216 # - ������� ������ ������� ��� � ������ ����� - ��� ����� ��� �������
217 # ������ ������ AUTOLOAD...
218 # ----------------------------------------------------------------------------
219 sub _init_
220 {
221 my $self = shift;
222
223 foreach my $attribute ( qw(
224 project project_version
225
226 httpd_port httpd_server httpd_root
227 data_directory data_dir
228 images_directory images_dir
229 session_directory session_dir
230 binary_directory binary_dir
231 crosslinks_directory crosslinks_dir
232
233 stage
234 db_keepalive db_host db_name db_user db_password db_port db_type db_client_encoding db_enable_utf8
235
236 db_encode_data db_decode_data
237
238 mason_comp
239 multidomain
240 project_name
241 preview
242
243 proxy_image_location
244 proxy_image_secret
245
246 debug
247 auth_cookie
248
249 plugins
250
251 development
252 is_dev_server
253
254 contenido_version version
255
256 store_method cascade
257
258 readonly
259
260 locale
261
262 memcached_enable memcached_servers
263 memcached_select_timeout
264 memcached_backend memcached_enable_compress
265 memcached_set_mode
266 memcached_object_expire
267 memcached_namespace
268 convert_binary
269 ) )
270 {
271 $self->{attributes}->{ $attribute } = 'SCALAR';
272 }
273 }
274
275
276
277 # ----------------------------------------------------------------------------
278 # ��� ����� AUTOLOAD. ����� ������� ��� ���������/������ �����...
279 # ������ 0.2
280 # ----------------------------------------------------------------------------
281
282 sub AUTOLOAD
283 {
284 my $self = shift;
285 my $attribute = $AUTOLOAD;
286
287 $attribute =~ s/.*:://;
288 return undef unless $attribute =~ /[^A-Z]/; # ��������� ������ ���� DESTROY
289
290 if (! exists($self->{attributes}->{$attribute}))
291 {
292 $log->error("����� ������, ��� �������� �� ���������� ��������������� ��������: ->$attribute()");
293 return undef;
294 }
295
296 $self->{ $attribute } = shift @_ if (scalar(@_) > 0);
297 return $self->{ $attribute };
298 }
299
300
301 1;