Mercurial > pub > Impl
annotate Lib/IMPL/Web/QueryHandler/PageFormat.pm @ 134:44977efed303
Significant performance optimizations
Fixed recursion problems due converting objects to JSON
Added cache support for the templates
Added discovery feature for the web methods
| author | wizard |
|---|---|
| date | Mon, 21 Jun 2010 02:39:53 +0400 |
| parents | e4f15cbc3f1a |
| children | f6af119ac741 |
| 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; |
| 116 | 16 public property pathinfoPrefix => prop_all; |
| 134 | 17 public property cache => prop_all; |
| 64 | 18 } |
| 19 | |
| 20 sub CTOR { | |
| 21 my ($this) = @_; | |
| 22 | |
| 65 | 23 $this->templatesCharset('utf-8') unless $this->templatesCharset; |
| 134 | 24 $this->cache(File::Spec->rel2abs($this->cache)) if $this->cache; |
| 25 $this->templatesBase(File::Spec->rel2abs($this->templatesBase)) if $this->templatesBase; | |
| 64 | 26 } |
| 27 | |
| 62 | 28 sub Process { |
| 29 my ($this,$action,$nextHandler) = @_; | |
| 30 | |
| 134 | 31 my $doc = new IMPL::Web::TT::Document(cache => $this->cache); |
| 62 | 32 |
|
63
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
62
diff
changeset
|
33 try { |
| 97 | 34 |
| 35 $this->templatesBase($ENV{DOCUMENT_ROOT}) unless $this->templatesBase; | |
| 36 | |
| 37 my $pathInfo = $ENV{PATH_INFO}; | |
| 116 | 38 my $prefixRoot = ""; |
| 39 if (my $rx = $this->pathinfoPrefix) { | |
| 40 $pathInfo =~ s/($rx)//; | |
| 41 $prefixRoot = $1 if $1; | |
| 42 } | |
| 43 local $ENV{PATH_INFO} = $pathInfo || $this->defaultTarget; | |
| 97 | 44 |
|
127
0dce0470a3d8
In the IMPL::Web::ControllerUnit added the ability to notify a form about a wrong data from a transaction
wizard
parents:
121
diff
changeset
|
45 my @path = grep $_, split /\//, ($ENV{PATH_INFO} || '') or die new IMPL::Exception("PATH_INFO is empty and no defaultTarget specified" ); |
|
0dce0470a3d8
In the IMPL::Web::ControllerUnit added the ability to notify a form about a wrong data from a transaction
wizard
parents:
121
diff
changeset
|
46 |
|
0dce0470a3d8
In the IMPL::Web::ControllerUnit added the ability to notify a form about a wrong data from a transaction
wizard
parents:
121
diff
changeset
|
47 my @pathContainer = @path; |
|
0dce0470a3d8
In the IMPL::Web::ControllerUnit added the ability to notify a form about a wrong data from a transaction
wizard
parents:
121
diff
changeset
|
48 pop @pathContainer; |
| 65 | 49 |
| 121 | 50 $doc->LoadFile ( File::Spec->catfile($this->templatesBase,@path), $this->templatesCharset, $this->templatesBase ); |
| 97 | 51 $doc->AddVar( result => $nextHandler->() ); |
| 129 | 52 $doc->AddVar( app => $action->application ); |
| 116 | 53 $doc->AddVar( absoluteUrl => sub { "$prefixRoot/$_[0]" } ); |
|
127
0dce0470a3d8
In the IMPL::Web::ControllerUnit added the ability to notify a form about a wrong data from a transaction
wizard
parents:
121
diff
changeset
|
54 $doc->AddVar( relativeUrl => sub { join '/', $prefixRoot, @pathContainer,$_[0] } ); |
| 97 | 55 { |
| 56 local $@; | |
| 116 | 57 $doc->AddVar( user => IMPL::Security::Context->current->principal ); |
| 58 $doc->AddVar( session => IMPL::Security::Context->current ); | |
| 97 | 59 warn $@ if $@; |
| 60 } | |
|
63
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
62
diff
changeset
|
61 |
|
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
62
diff
changeset
|
62 $action->response->contentType('text/html'); |
|
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
62
diff
changeset
|
63 my $hOut = $action->response->streamBody; |
|
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
62
diff
changeset
|
64 print $hOut $doc->Render(); |
|
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
62
diff
changeset
|
65 } finally { |
|
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
62
diff
changeset
|
66 $doc->Dispose; |
|
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
62
diff
changeset
|
67 }; |
| 62 | 68 } |
| 69 | |
| 65 | 70 1; |
| 71 | |
| 72 __END__ | |
| 73 | |
| 74 =pod | |
| 75 | |
| 76 =head1 NAME | |
| 77 | |
| 78 C<IMPL::Web::QueryHandler::PageFormat> - Выдача результатов в виде HTML страницы, построенной из шаблона. | |
| 79 | |
| 80 =head1 SYNOPSIS | |
| 81 | |
| 82 В файле конфигурации приложения | |
| 83 | |
| 84 =begin code xml | |
| 85 | |
| 86 <handlersQuery type="IMPL::Object::List"> | |
| 87 <item type="IMPL::Web::QueryHandler::PageFormat"> | |
| 88 <charsetTemplates>utf-8</charsetTemplates> | |
| 89 </item> | |
| 90 </handlersQuery> | |
| 91 | |
| 92 =end code xml | |
| 93 | |
| 94 Программно | |
| 95 | |
| 96 =begin code | |
| 97 | |
| 98 my $app = new IMPL::Web::Application(); | |
| 99 $app->handlersQuery->Add( | |
| 100 new IMPL::Web::QueryHandler::PageFormat( charsetTemplates=> 'utf-8' ); | |
| 101 ); | |
| 102 | |
| 103 =end | |
| 104 | |
| 105 =head1 DESCRIPTION | |
| 106 | |
| 107 Обработчик запроса для веб приложения. Загружает шаблон, путь к котрому берется | |
| 108 из C<ENV{PATH_INFO}> относительно пути из свойства C<templatesBase>. | |
| 109 | |
| 110 Наследуется от C<IMPL::Web::QueryHandler> для реализации функционала | |
| 111 обработчика запроса и переопределяет метод C<Process>. | |
| 112 | |
| 113 C<Serializable> | |
| 114 | |
| 115 =head1 MEMBERS | |
| 116 | |
| 117 =over | |
| 118 | |
| 119 =item C<CTOR(%props)> | |
| 120 | |
| 121 Создает новый экземпляр и заполняет свойства. | |
| 122 | |
| 123 =item C<[get,set] templatesCharset> | |
| 124 | |
| 125 Кодировка шаблонов. По умолчанию utf-8. | |
| 126 | |
| 127 =item C<[get,set] templatesBase> | |
| 128 | |
| 129 Каталог относительно которого ищется шаблон. | |
| 130 | |
| 131 =item C<[override] Process($action,$nextHandler)> | |
| 132 | |
| 133 Метод, переопределяющий C<IMPL::Web::QueryHandler->Process> и которому передается управление | |
| 134 для выполнения действий. | |
| 135 | |
| 136 =back | |
| 137 | |
| 138 =cut |
