Mercurial > pub > Impl
comparison Lib/IMPL/Web/Application.pm @ 97:964587c5183c
Added SecureCall to Web QueryHandlers stack
many bug fixes to Security and Web Application modules
| author | wizard |
|---|---|
| date | Tue, 04 May 2010 04:04:37 +0400 |
| parents | 2f31ecabe9ea |
| children | 6dd659f6f66c |
comparison
equal
deleted
inserted
replaced
| 96:4c55aed00ff2 | 97:964587c5183c |
|---|---|
| 17 public property actionFactory => prop_all; | 17 public property actionFactory => prop_all; |
| 18 public property handlersQuery => prop_all | prop_list; | 18 public property handlersQuery => prop_all | prop_list; |
| 19 public property responseCharset => prop_all; | 19 public property responseCharset => prop_all; |
| 20 public property security => prop_all; | 20 public property security => prop_all; |
| 21 public property options => prop_all; | 21 public property options => prop_all; |
| 22 public property fetchRequestMethod => prop_all; | |
| 22 } | 23 } |
| 23 | 24 |
| 24 sub CTOR { | 25 sub CTOR { |
| 25 my ($this) = @_; | 26 my ($this) = @_; |
| 26 | 27 |
| 27 $this->actionFactory('IMPL::Web::Application::Action') unless $this->actionFactory; | 28 $this->actionFactory('IMPL::Web::Application::Action') unless $this->actionFactory; |
| 28 $this->responseCharset('utf-8') unless $this->responseCharset; | 29 $this->responseCharset('utf-8') unless $this->responseCharset; |
| 30 $this->fetchRequestMethod(\&defaultFetchRequest) unless $this->fetchRequestMethod; | |
| 31 $this->handlerError(\&defaultHandlerError) unless $this->handlerError; | |
| 29 } | 32 } |
| 30 | 33 |
| 31 sub Run { | 34 sub Run { |
| 32 my ($this) = @_; | 35 my ($this) = @_; |
| 33 | 36 |
| 36 my $action = $this->actionFactory->new( | 39 my $action = $this->actionFactory->new( |
| 37 query => $query, | 40 query => $query, |
| 38 application => $this, | 41 application => $this, |
| 39 ); | 42 ); |
| 40 | 43 |
| 41 $action->response->charset($this->responseCharset); | 44 eval { |
| 42 | 45 $action->response->charset($this->responseCharset); |
| 43 $action->ChainHandler($_) foreach $this->handlersQuery; | 46 |
| 44 | 47 $action->ChainHandler($_) foreach $this->handlersQuery; |
| 45 $action->Invoke(); | 48 |
| 46 | 49 $action->Invoke(); |
| 47 $action->response->Complete; | 50 |
| 51 $action->response->Complete; | |
| 52 }; | |
| 53 if ($@) { | |
| 54 my $e = $@; | |
| 55 eval { $this->handlerError()->($this,$action,$e); 1;} or warn "Error in handlerError: ",$@; | |
| 56 } | |
| 48 } | 57 } |
| 58 } | |
| 59 | |
| 60 sub FetchRequest { | |
| 61 my ($this) = @_; | |
| 62 | |
| 63 if( ref $this->fetchRequestMethod eq 'CODE' ) { | |
| 64 return $this->fetchRequestMethod->($this); | |
| 65 } else { | |
| 66 die new IMPL::Exception("Unknown fetchRequestMethod type",ref $this->fetchRequestMethod); | |
| 67 } | |
| 49 } | 68 } |
| 50 | 69 |
| 51 { | 70 { |
| 52 my $hasFetched = 0; | 71 my $hasFetched = 0; |
| 53 | 72 |
| 54 sub FetchRequest { | 73 sub defaultFetchRequest { |
| 55 return undef if $hasFetched; | 74 return undef if $hasFetched; |
| 56 $hasFetched = 1; | 75 $hasFetched = 1; |
| 57 return CGI->new(); | 76 return CGI->new(); |
| 58 } | 77 } |
| 78 } | |
| 79 | |
| 80 sub defaultHandlerError { | |
| 81 my ($this,$action,$e) = @_; | |
| 82 warn $e; | |
| 83 if ( eval { $action->ReinitResponse(); 1; } ) { | |
| 84 $action->response->contentType('text/plain'); | |
| 85 $action->response->charset($this->responseCharset); | |
| 86 $action->response->status(500); | |
| 87 my $hout = $action->response->streamBody; | |
| 88 print $hout $e; | |
| 89 $action->response->Complete(); | |
| 90 } | |
| 59 } | 91 } |
| 60 | 92 |
| 61 1; | 93 1; |
| 62 | 94 |
| 63 __END__ | 95 __END__ |
| 197 application => $this, | 229 application => $this, |
| 198 ); | 230 ); |
| 199 | 231 |
| 200 =end code | 232 =end code |
| 201 | 233 |
| 234 =item C< [get,set] fetchRequestMethod > | |
| 235 | |
| 236 Метод получения CGI запроса. Возвращает C<CGI> объект следующего запроса, если | |
| 237 запросов больше нет, то возвращает C<undef>. По-умолчанию использует C<defaultFetchRequest>. | |
| 238 | |
| 239 Может быть как ссылкой на функцию, так и объектом типа C<IMPL::Web::Application::RequestFetcher>. | |
| 240 | |
| 202 =item C< [get,set,list] handlersQuery > | 241 =item C< [get,set,list] handlersQuery > |
| 203 | 242 |
| 204 Список обработчиков запросов, которые будут переданы созданному объекту-действию. | 243 Список обработчиков запросов, которые будут переданы созданному объекту-действию. |
| 205 | 244 |
| 206 =item C< [get,set] responseCharset> | 245 =item C< [get,set] responseCharset> |
