diff Lib/IMPL/Web/Application.pm @ 244:a02b110da931

refactoring fixed binding to CGI query parameters with multiple values
author sergey
date Mon, 22 Oct 2012 04:09:27 +0400
parents fe9d62d9054d
children 546957c50a36
line wrap: on
line diff
--- a/Lib/IMPL/Web/Application.pm	Fri Oct 19 02:23:15 2012 +0400
+++ b/Lib/IMPL/Web/Application.pm	Mon Oct 22 04:09:27 2012 +0400
@@ -8,6 +8,7 @@
 
 use IMPL::declare {
 	require => {
+	    Locator                   => 'IMPL::Web::AutoLocator',
 		TAction                   => 'IMPL::Web::Application::Action',
 		HttpResponse              => 'IMPL::Web::HttpResponse',
 		TFactory                  => '-IMPL::Object::Factory',
@@ -20,13 +21,14 @@
 		'IMPL::Object::Singleton' => '@_'
 	  ],
 	  props => [
+	    baseUrl            => PROP_RW,
 		actionFactory      => PROP_RW,
 		handlers           => PROP_RW | PROP_LIST,
 		security           => PROP_RW,
 		options            => PROP_RW,
 		requestCharset     => PROP_RW,
-		fetchRequestMethod => PROP_RW,
-		output             => PROP_RW
+		output             => PROP_RW,
+		location           => PROP_RO
 	  ]
 };
 
@@ -37,9 +39,10 @@
 		"At least one handler should be supplied" )
 	  unless $this->handlers->Count;
 
+    $this->baseUrl('/') unless $this->baseUrl;
+    
 	$this->actionFactory(TAction) unless $this->actionFactory;
-	$this->fetchRequestMethod( \&defaultFetchRequest )
-	  unless $this->fetchRequestMethod;
+	$this->location(Locator->new(base => $this->baseUrl));
 }
 
 sub Run {
@@ -125,86 +128,8 @@
 }
 
 sub FetchRequest {
-	my ($this) = @_;
-
-	if ( ref $this->fetchRequestMethod eq 'CODE' ) {
-		return $this->fetchRequestMethod->($this);
-	}
-	else {
-		die new IMPL::Exception(
-			"Unknown fetchRequestMethod type",
-			ref $this->fetchRequestMethod
-		);
-	}
-}
-
-{
-	my $hasFetched = 0;
-
-	sub defaultFetchRequest {
-		my ($this) = @_;
-		return undef if $hasFetched;
-		$hasFetched = 1;
-		$this->output(*STDOUT);
-		my $query = CGIWrapper->new();
-		$query->charset($this->requestCharset) if $this->requestCharset;
-		return $query;
-	}
-}
-
-sub defaultErrorHandler {
-	my ( $this, $action, $e ) = @_;
-	warn $e;
-	if ( eval { $action->ReinitResponse(); 1; } ) {
-		$action->response->contentType('text/plain');
-		$action->response->charset( $this->responseCharset );
-		$action->response->status(500);
-		my $hout = $action->response->streamBody;
-		print $hout $e;
-		$action->response->Complete();
-	}
-}
-
-package CGIWrapper;
-use parent qw(CGI);
-
-use Encode;
-
-our $NO_DECODE = 0;
-
-sub param {
-	my $this = shift;
-
-	return $this->SUPER::param(@_) if $NO_DECODE;
-
-	if (wantarray) {
-		my @result = $this->SUPER::param(@_);
-
-		return map Encode::is_utf8($_)
-		  ? $_
-		  : Encode::decode( $this->charset, $_, Encode::LEAVE_SRC ), @result;
-	}
-	else {
-		my $result = $this->SUPER::param(@_);
-
-		return Encode::is_utf8($result)
-		  ? $result
-		  : Encode::decode( $this->charset, $result, Encode::LEAVE_SRC );
-	}
-
-}
-
-sub upload {
-	my $this = shift;
-
-	local $NO_DECODE = 1;
-	my $oldCharset = $this->charset();
-	$this->charset('ISO-8859-1');
-
-	my $fh = $this->SUPER::upload(@_);
-
-	$this->charset($oldCharset);
-	return $fh;
+    
+    return;
 }
 
 1;
@@ -215,7 +140,7 @@
 
 =head1 NAME
 
-C<IMPL::Web::Application> Класс для создания экземпляров приложения
+C<IMPL::Web::Application> Базовай класс для создания экземпляров приложения
 
 =head1 SYNOPSIS
 
@@ -241,4 +166,6 @@
 обработчиков. Цепочка обработчиков вызывается снизу вверх, при этом каждый
 обработчик самостоятельно рекурсивно вызывает следующий (более высокого уровня).
 
+См. также C<IMPL::Web::CGIApplication>
+
 =cut