| 1 |
3 |
ahitrov@rambler.ru |
#!/usr/bin/perl |
| 2 |
|
|
|
| 3 |
|
|
use strict; |
| 4 |
|
|
|
| 5 |
|
|
use Apache; |
| 6 |
|
|
use Apache::Constants; |
| 7 |
|
|
use Time::HiRes; |
| 8 |
|
|
|
| 9 |
|
|
use Contenido::Globals; |
| 10 |
|
|
use Contenido::Apache; |
| 11 |
|
|
use Contenido::Init; |
| 12 |
|
|
|
| 13 |
|
|
$Contenido::Globals::PROJECT_NAME = '@PROJECT@'; |
| 14 |
|
|
$store_method = lc('@STORE_METHOD@'); |
| 15 |
|
|
$DEBUG = lc('@DEBUG@') eq 'yes'; |
| 16 |
|
|
$DEBUG_SQL = lc('@DEBUG_SQL@') eq 'yes'; |
| 17 |
|
|
$DEBUG_CORE = lc('@DEBUG_CORE@') eq 'yes'; |
| 18 |
|
|
|
| 19 |
|
|
#������� ������������� Contenido |
| 20 |
|
|
Contenido::Init->init(); |
| 21 |
|
|
|
| 22 |
|
|
#�������� ��� ��� ����� � ����� � ������� �������� ���������� |
| 23 |
|
|
package HTML::Mason::Commands; |
| 24 |
|
|
|
| 25 |
|
|
use Data::Dumper; |
| 26 |
|
|
use CGI::Cookie; |
| 27 |
|
|
use Convert::Cyrillic; |
| 28 |
|
|
use Image::Size; |
| 29 |
|
|
use Time::HiRes qw(gettimeofday); |
| 30 |
|
|
use POSIX qw(strftime); |
| 31 |
|
|
use Contenido::File; |
| 32 |
|
|
use Contenido::DateTime; |
| 33 |
|
|
|
| 34 |
|
|
use Utils; |
| 35 |
|
|
use Contenido::Globals; |
| 36 |
|
|
use Contenido::Init; |
| 37 |
|
|
|
| 38 |
|
|
use vars qw(%_comments); |
| 39 |
|
|
|
| 40 |
|
|
%_comments = ( |
| 41 |
|
|
'text/css' => ['/*', '*/' ], |
| 42 |
|
|
'text/html' => ['<!--', '-->'], |
| 43 |
|
|
); |
| 44 |
|
|
|
| 45 |
|
|
require "@CONF@/mason/handler_project.pl"; |
| 46 |
|
|
|
| 47 |
|
|
1; |
| 48 |
|
|
|
| 49 |
|
|
#���������� package � ������� �������� �������� handler |
| 50 |
|
|
package @PROJECT@::Mason; |
| 51 |
|
|
|
| 52 |
|
|
use Contenido::Globals; |
| 53 |
|
|
use HTML::Mason::ApacheHandler; |
| 54 |
|
|
use HTML::Entities; |
| 55 |
|
|
use Utils; |
| 56 |
|
|
|
| 57 |
|
|
my %ah_args = ( |
| 58 |
|
|
data_dir => '@PROJECT_VAR@/mason', |
| 59 |
|
|
comp_root => [['project'=>'@MASON_COMP@'], ['core'=>'@CORE_COMP@']], |
| 60 |
|
|
); |
| 61 |
|
|
|
| 62 |
|
|
if ( '@PLUGINS@' ) { |
| 63 |
|
|
my @plcomps = map { [$_=>'@PLUGIN_COMP@'.'/'.$_.'/comps'] } grep { $_ } split(/\ +/, '@PLUGINS@'); |
| 64 |
|
|
if ( @plcomps ) { |
| 65 |
|
|
@{$ah_args{comp_root}} = ($ah_args{comp_root}->[0], @plcomps, $ah_args{comp_root}->[1]); |
| 66 |
|
|
} |
| 67 |
|
|
} |
| 68 |
|
|
|
| 69 |
|
|
if (lc('@DEVELOPMENT@') eq 'yes') { |
| 70 |
|
|
$ah_args{error_mode} = 'output'; |
| 71 |
|
|
|
| 72 |
|
|
if (lc '@COMP_TIMINGS_DISABLE@' ne 'yes') { |
| 73 |
|
|
$ah_args{preamble} = q| |
| 74 |
|
|
use locale; |
| 75 |
|
|
my $_comm = $_comments{$r->content_type}; |
| 76 |
|
|
my $s_time_ = [Time::HiRes::gettimeofday]; |
| 77 |
|
|
if ($_comm) { |
| 78 |
|
|
$m->out("\n".$$_comm[0]." ".$m->current_comp->path.":\tStart t: ".Time::HiRes::time." ".$$_comm[1]."\n"); |
| 79 |
|
|
}|; |
| 80 |
|
|
$ah_args{postamble} = q| |
| 81 |
|
|
if ($_comm) { |
| 82 |
|
|
$m->out("\n".$$_comm[0]." ".$m->current_comp->path.":\tFinish t: ".Time::HiRes::time.", w: ".sprintf('%.4f', Time::HiRes::tv_interval($s_time_))." ".$$_comm[1]."\n"); |
| 83 |
|
|
}|; |
| 84 |
|
|
} else { |
| 85 |
|
|
$ah_args{preamble} = q| |
| 86 |
|
|
use locale; |
| 87 |
|
|
|; |
| 88 |
|
|
} |
| 89 |
|
|
} else { |
| 90 |
|
|
$ah_args{preamble} = q| |
| 91 |
|
|
use locale; |
| 92 |
|
|
|; |
| 93 |
|
|
$ah_args{error_mode} = lc('@ERROR_MODE@') eq 'output' ? 'output':'fatal'; |
| 94 |
|
|
$ah_args{preloads} = [qw(@PRELOADS@)]; |
| 95 |
|
|
if (lc('@STATIC_SOURCE_ENABLE@') eq 'yes') { |
| 96 |
|
|
$ah_args{static_source} = 1; |
| 97 |
|
|
} |
| 98 |
|
|
} |
| 99 |
|
|
|
| 100 |
|
|
if ( lc '@PREAMBLE_HANDLER@' and ref $state->{preamble_handler_obj} ) { |
| 101 |
|
|
$ah_args{preamble} .= q| |
| 102 |
|
|
{ |
| 103 |
|
|
my $ret = $state->{preamble_handler_obj}->handle( $m, \@_ ); |
| 104 |
|
|
if ( ref $ret eq 'HASH' ) { |
| 105 |
|
|
return if ($ret->{_cached} or $ret->{_return}); # component is self cached or wanna return |
| 106 |
|
|
&http_abort( $ret->{http_abort} ) if $ret->{http_abort}; |
| 107 |
|
|
} |
| 108 |
|
|
} |
| 109 |
|
|
|; |
| 110 |
|
|
} |
| 111 |
|
|
|
| 112 |
|
|
#������ ��� ������ perl � ��������� :( |
| 113 |
|
|
if (@PERL_LEVEL@ >= 500600) { |
| 114 |
|
|
$ah_args{buffer_preallocate_size} = 256000; |
| 115 |
|
|
$ah_args{enable_autoflush} = 0; |
| 116 |
|
|
} |
| 117 |
|
|
|
| 118 |
|
|
# ����������� Mason (� ��������) |
| 119 |
|
|
if (lc '@MASON_CACHE_ENABLED@' eq 'yes') { |
| 120 |
|
|
# ����������� Mason ����������� Memcached |
| 121 |
|
|
if (lc '@MASON_MEMCACHED_ENABLED@' eq 'yes') { |
| 122 |
|
|
$ah_args{data_cache_defaults} = { |
| 123 |
|
|
cache_class => 'Contenido::Cache::Memcached', |
| 124 |
|
|
mc_backend => '@MASON_MEMCACHED_BACKEND@', |
| 125 |
|
|
mc_servers => [qw(@MASON_MEMCACHED_SERVERS@)], |
| 126 |
|
|
mc_debug => lc '@MASON_MEMCACHED_DEBUG@' eq 'yes', |
| 127 |
|
|
mc_namespace => '@MASON_MEMCACHED_NAMESPACE@', |
| 128 |
|
|
}; |
| 129 |
|
|
} |
| 130 |
|
|
} else { |
| 131 |
|
|
$ah_args{data_cache_defaults} = { |
| 132 |
|
|
cache_class => 'Cache::NullCache', |
| 133 |
|
|
}; |
| 134 |
|
|
} |
| 135 |
|
|
|
| 136 |
|
|
$ah_args{escape_flags} = { |
| 137 |
|
|
h => sub { HTML::Entities::encode_entities(${ $_[0] }, '\'<>&"') }, |
| 138 |
|
|
js => sub { Utils::js_escape( ${ $_[0] } ) }, |
| 139 |
|
|
strip_crlf => sub { ${$_[0]} =~ s/\r?\n\s*/ /g }, |
| 140 |
|
|
}; |
| 141 |
|
|
|
| 142 |
|
|
$ah_args{default_escape_flags} = '@DEFAULT_ESCAPE_FLAGS@' unless '@DEFAULT_ESCAPE_FLAGS@' eq ''; |
| 143 |
|
|
|
| 144 |
|
|
# ����������� ������������ ��������� |
| 145 |
|
|
if (lc '@COMP_CACHE_ENABLED@' eq 'no') { |
| 146 |
|
|
$ah_args{use_object_files} = 0; |
| 147 |
|
|
$ah_args{code_cache_max_size} = 0; |
| 148 |
|
|
} |
| 149 |
|
|
|
| 150 |
|
|
my $ah =new @DEFAULT_HANDLER@(%ah_args); |
| 151 |
|
|
|
| 152 |
|
|
sub handler { |
| 153 |
|
|
my $r = shift; |
| 154 |
|
|
|
| 155 |
|
|
# Mason �� ������������ ������ �!!!! /i/ /images/ /binary/ |
| 156 |
|
|
return Apache::Constants::DECLINED unless Contenido::Apache::is_valid_request($r); |
| 157 |
|
|
|
| 158 |
|
|
my $status; |
| 159 |
|
|
|
| 160 |
|
|
# ������������� ���������� � ����� ��� ������� � ���� ������������ ��������, |
| 161 |
|
|
# ���� �� ��� ��� ��� ���� �������� |
| 162 |
|
|
# � �������� ���������� ������ |
| 163 |
|
|
eval { |
| 164 |
|
|
Contenido::Apache::request_init($r); |
| 165 |
|
|
$status = $ah->handle_request($r) |
| 166 |
|
|
}; |
| 167 |
|
|
|
| 168 |
|
|
if ($@) { |
| 169 |
|
|
warn '['.scalar(localtime())."] got error $@\n"; |
| 170 |
|
|
return Apache::Constants::SERVER_ERROR; |
| 171 |
|
|
} else { |
| 172 |
|
|
return $status; |
| 173 |
|
|
} |
| 174 |
|
|
} |
| 175 |
|
|
|
| 176 |
|
|
|
| 177 |
|
|
1; |
| 178 |
|
|
|