Mercurial > pub > Impl
annotate Lib/IMPL/Web/QueryHandler/PageFormat.pm @ 111:6c25ea91c985
ControllerUnit concept
author | wizard |
---|---|
date | Tue, 18 May 2010 01:33:37 +0400 |
parents | 0e72ad99eef7 |
children | 1722ca51537c |
rev | line source |
---|---|
62 | 1 package IMPL::Web::QueryHandler::PageFormat; |
64 | 2 use base qw(IMPL::Web::QueryHandler IMPL::Object::Autofill); |
62 | 3 |
4 __PACKAGE__->PassThroughArgs; | |
5 | |
6 use IMPL::Class::Property; | |
77 | 7 use IMPL::Web::TT::Document; |
97 | 8 use IMPL::Security::Context; |
65 | 9 use File::Spec; |
63
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
62
diff
changeset
|
10 use Error qw(:try); |
62 | 11 |
64 | 12 BEGIN { |
65 | 13 public property templatesCharset => prop_all; |
14 public property templatesBase => prop_all; | |
97 | 15 public property defaultTarget => prop_all; |
64 | 16 } |
17 | |
18 sub CTOR { | |
19 my ($this) = @_; | |
20 | |
65 | 21 $this->templatesCharset('utf-8') unless $this->templatesCharset; |
64 | 22 } |
23 | |
62 | 24 sub Process { |
25 my ($this,$action,$nextHandler) = @_; | |
26 | |
77 | 27 my $doc = new IMPL::Web::TT::Document(); |
62 | 28 |
63
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
62
diff
changeset
|
29 try { |
97 | 30 |
31 $this->templatesBase($ENV{DOCUMENT_ROOT}) unless $this->templatesBase; | |
32 | |
33 my $pathInfo = $ENV{PATH_INFO}; | |
34 local $ENV{PATH_INFO} = $pathInfo || $this->defaultTarget; | |
35 | |
36 my @path = split /\//, ($ENV{PATH_INFO} || '') or die new IMPL::Exception("PATH_INFO is empty and no defaultTarget specified" ); | |
65 | 37 |
77 | 38 $doc->LoadFile ( File::Spec->catfile($this->templatesBase,@path), $this->templatesCharset ); |
97 | 39 $doc->AddVar( result => $nextHandler->() ); |
107 | 40 $doc->AddVar( absoluteUrl => sub { "/$_[0]" } ); |
97 | 41 { |
42 local $@; | |
43 $doc->AddVar( user => eval { IMPL::Security::Context->current->principal; } ); | |
44 $doc->AddVar( session => eval { IMPL::Security::Context->current; } ); | |
45 warn $@ if $@; | |
46 } | |
63
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
62
diff
changeset
|
47 |
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
62
diff
changeset
|
48 $action->response->contentType('text/html'); |
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
62
diff
changeset
|
49 my $hOut = $action->response->streamBody; |
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
62
diff
changeset
|
50 print $hOut $doc->Render(); |
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
62
diff
changeset
|
51 } finally { |
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
62
diff
changeset
|
52 $doc->Dispose; |
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
62
diff
changeset
|
53 }; |
62 | 54 } |
55 | |
65 | 56 1; |
57 | |
58 __END__ | |
59 | |
60 =pod | |
61 | |
62 =head1 NAME | |
63 | |
64 C<IMPL::Web::QueryHandler::PageFormat> - Выдача результатов в виде HTML страницы, построенной из шаблона. | |
65 | |
66 =head1 SYNOPSIS | |
67 | |
68 В файле конфигурации приложения | |
69 | |
70 =begin code xml | |
71 | |
72 <handlersQuery type="IMPL::Object::List"> | |
73 <item type="IMPL::Web::QueryHandler::PageFormat"> | |
74 <charsetTemplates>utf-8</charsetTemplates> | |
75 </item> | |
76 </handlersQuery> | |
77 | |
78 =end code xml | |
79 | |
80 Программно | |
81 | |
82 =begin code | |
83 | |
84 my $app = new IMPL::Web::Application(); | |
85 $app->handlersQuery->Add( | |
86 new IMPL::Web::QueryHandler::PageFormat( charsetTemplates=> 'utf-8' ); | |
87 ); | |
88 | |
89 =end | |
90 | |
91 =head1 DESCRIPTION | |
92 | |
93 Обработчик запроса для веб приложения. Загружает шаблон, путь к котрому берется | |
94 из C<ENV{PATH_INFO}> относительно пути из свойства C<templatesBase>. | |
95 | |
96 Наследуется от C<IMPL::Web::QueryHandler> для реализации функционала | |
97 обработчика запроса и переопределяет метод C<Process>. | |
98 | |
99 C<Serializable> | |
100 | |
101 =head1 MEMBERS | |
102 | |
103 =over | |
104 | |
105 =item C<CTOR(%props)> | |
106 | |
107 Создает новый экземпляр и заполняет свойства. | |
108 | |
109 =item C<[get,set] templatesCharset> | |
110 | |
111 Кодировка шаблонов. По умолчанию utf-8. | |
112 | |
113 =item C<[get,set] templatesBase> | |
114 | |
115 Каталог относительно которого ищется шаблон. | |
116 | |
117 =item C<[override] Process($action,$nextHandler)> | |
118 | |
119 Метод, переопределяющий C<IMPL::Web::QueryHandler->Process> и которому передается управление | |
120 для выполнения действий. | |
121 | |
122 =back | |
123 | |
124 =cut |