diff Lib/IMPL/Web/Application.pm @ 194:4d0e1962161c

Replaced tabs with spaces IMPL::Web::View - fixed document model, new features (control classes, document constructor parameters)
author cin
date Tue, 10 Apr 2012 20:08:29 +0400
parents d1676be8afcc
children 2ffe6f661605
line wrap: on
line diff
--- a/Lib/IMPL/Web/Application.pm	Tue Apr 10 08:13:22 2012 +0400
+++ b/Lib/IMPL/Web/Application.pm	Tue Apr 10 20:08:29 2012 +0400
@@ -22,12 +22,12 @@
 
 
 sub CTOR {
-	my ($this) = @_;
-	
-	$this->actionFactory(typeof IMPL::Web::Application::Action) unless $this->actionFactory;
-	$this->responseCharset('utf-8') unless $this->responseCharset;
-	$this->fetchRequestMethod(\&defaultFetchRequest) unless $this->fetchRequestMethod;
-	$this->handlerError(\&defaultHandlerError) unless $this->handlerError;
+    my ($this) = @_;
+    
+    $this->actionFactory(typeof IMPL::Web::Application::Action) unless $this->actionFactory;
+    $this->responseCharset('utf-8') unless $this->responseCharset;
+    $this->fetchRequestMethod(\&defaultFetchRequest) unless $this->fetchRequestMethod;
+    $this->handlerError(\&defaultHandlerError) unless $this->handlerError;
 }
 
 sub Run {
@@ -36,61 +36,61 @@
     while (my $query = $this->FetchRequest()) {
         
         my $action = $this->actionFactory->new(
-        	query => $query,
-        	application => $this, 
+            query => $query,
+            application => $this, 
         );
         
         eval {
-	        $action->response->charset($this->responseCharset);
-	        
-	        $action->ChainHandler($_) foreach $this->handlersQuery;
-	        
-	        $action->Invoke();
-	        
-	        $action->response->Complete;
+            $action->response->charset($this->responseCharset);
+            
+            $action->ChainHandler($_) foreach $this->handlersQuery;
+            
+            $action->Invoke();
+            
+            $action->response->Complete;
         };
         if ($@) {
-        	my $e = $@;
-        	# we are expecting this method to be safe otherwise we can trust nothing in this wolrd 
-        	$this->handlerError()->($this,$action,$e);
+            my $e = $@;
+            # we are expecting this method to be safe otherwise we can trust nothing in this wolrd 
+            $this->handlerError()->($this,$action,$e);
         }
     }
 }
 
 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 ($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;
+    my $hasFetched = 0;
 
-	sub defaultFetchRequest {
-		my ($this) = @_;
-		return undef if $hasFetched;
-		$hasFetched = 1;
-		my $query = CGIWrapper->new();
-		$query->charset($this->responseCharset);
-		return $query;
-	}
+    sub defaultFetchRequest {
+        my ($this) = @_;
+        return undef if $hasFetched;
+        $hasFetched = 1;
+        my $query = CGIWrapper->new();
+        $query->charset($this->responseCharset);
+        return $query;
+    }
 }
 
 sub defaultHandlerError {
-	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();
-	}	
+    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;
@@ -101,33 +101,33 @@
 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);
-	}
+    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;
+    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;
 }
 
 1;
@@ -190,60 +190,60 @@
 
 <?xml version="1.0" encoding="UTF-8"?>
 <Application id='app' type="Test::Web::Application::Instance">
-	
-	<!-- Begin custom properties -->
-	<name>Sample application</name>
-	<dataSource type='IMPL::Config::Activator' id='ds'>
-		<factory>IMPL::Object</factory>
-		<parameters type='HASH'>
-			<db>data</db>
-			<user>nobody</user>
-		</parameters>
-	</dataSource>
-	<securityMod type='IMPL::Config::Activator'>
-		<factory>IMPL::Object</factory>
-		<parameters type='HASH'>
-			<ds refid='ds'/>
-		</parameters>
-	</securityMod>	
-	<!-- End custom properties -->
-	
-	<!-- direct access to the activators -->
-	<options type="HASH">
-		<dataSource refid='ds'/>
-	</options>
-	
-	<!-- Set default output encoding, can be changed due query handling -->
-	<responseCharset>utf-8</responseCharset>
-	
-	<!-- Actions creation configuration -->
-	<actionFactory type="IMPL::Object::Factory">
-		
-		<!-- Construct actions -->		
-		<factory>IMPL::Web::Application::Action</factory>
-		<parameters type='HASH'>
-			
-			<!-- with special responseFactory -->
-			<responseFactory type='IMPL::Object::Factory'>
-			
-				<!-- Where resopnses have a special streamOut -->
-				<factory>IMPL::Web::Application::Response</factory>
-				<parameters type='HASH'>
-				
-					<!-- in memory dummy output instead of STDOUT -->
-					<streamOut>memory</streamOut>
-					
-				</parameters>
-			</responseFactory>
-		</parameters>
-	</actionFactory>
-	
-	<!-- Query processing chain -->
-	<handlersQuery type="IMPL::Object::List">
-		<item type="IMPL::Web::QueryHandler::PageFormat">
-			<templatesCharset>cp1251</templatesCharset>
-		</item>
-	</handlersQuery>
+    
+    <!-- Begin custom properties -->
+    <name>Sample application</name>
+    <dataSource type='IMPL::Config::Activator' id='ds'>
+        <factory>IMPL::Object</factory>
+        <parameters type='HASH'>
+            <db>data</db>
+            <user>nobody</user>
+        </parameters>
+    </dataSource>
+    <securityMod type='IMPL::Config::Activator'>
+        <factory>IMPL::Object</factory>
+        <parameters type='HASH'>
+            <ds refid='ds'/>
+        </parameters>
+    </securityMod>    
+    <!-- End custom properties -->
+    
+    <!-- direct access to the activators -->
+    <options type="HASH">
+        <dataSource refid='ds'/>
+    </options>
+    
+    <!-- Set default output encoding, can be changed due query handling -->
+    <responseCharset>utf-8</responseCharset>
+    
+    <!-- Actions creation configuration -->
+    <actionFactory type="IMPL::Object::Factory">
+        
+        <!-- Construct actions -->        
+        <factory>IMPL::Web::Application::Action</factory>
+        <parameters type='HASH'>
+            
+            <!-- with special responseFactory -->
+            <responseFactory type='IMPL::Object::Factory'>
+            
+                <!-- Where resopnses have a special streamOut -->
+                <factory>IMPL::Web::Application::Response</factory>
+                <parameters type='HASH'>
+                
+                    <!-- in memory dummy output instead of STDOUT -->
+                    <streamOut>memory</streamOut>
+                    
+                </parameters>
+            </responseFactory>
+        </parameters>
+    </actionFactory>
+    
+    <!-- Query processing chain -->
+    <handlersQuery type="IMPL::Object::List">
+        <item type="IMPL::Web::QueryHandler::PageFormat">
+            <templatesCharset>cp1251</templatesCharset>
+        </item>
+    </handlersQuery>
 </Application>
 
 =end code xml