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