diff Lib/IMPL/Web/Application/Response.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 f534a60d5b01
line wrap: on
line diff
--- a/Lib/IMPL/Web/Application/Response.pm	Tue Apr 10 08:13:22 2012 +0400
+++ b/Lib/IMPL/Web/Application/Response.pm	Tue Apr 10 20:08:29 2012 +0400
@@ -14,174 +14,174 @@
 #todo: add binary method to set a binary encoding, set it automatic when type isn't a text 
 
 BEGIN {
-	# автозаполнение буде происходить в порядке объявления
-	public property query => prop_get | owner_set; # cgi query
-	public property status => prop_all, { validator => \&_checkHeaderPrinted };
-	public property contentType => prop_all, { validator => \&_checkHeaderPrinted }; # String
-	public property charset => { get => \&_charset, set => \&_charset }, { validator => \&_checkHeaderPrinted };
-	public property expires => prop_all, { validator => \&_checkHeaderPrinted };
-	public property cookies => prop_all, { validator => \&_checkHeaderPrinted }; # Hash
-	
-	public property buffered => prop_all, { validator => \&_canChangeBuffer }; # Boolean
-	public property streamOut => prop_get | owner_set; # stream
-	public property streamBody => {get => \&getStreamBody }; # stream
-	public property isHeaderPrinted => prop_get | owner_set; # Boolean 
-	
-	private property _bufferBody => prop_all;
-	private property _streamBody => prop_all;
+    # автозаполнение буде происходить в порядке объявления
+    public property query => prop_get | owner_set; # cgi query
+    public property status => prop_all, { validator => \&_checkHeaderPrinted };
+    public property contentType => prop_all, { validator => \&_checkHeaderPrinted }; # String
+    public property charset => { get => \&_charset, set => \&_charset }, { validator => \&_checkHeaderPrinted };
+    public property expires => prop_all, { validator => \&_checkHeaderPrinted };
+    public property cookies => prop_all, { validator => \&_checkHeaderPrinted }; # Hash
+    
+    public property buffered => prop_all, { validator => \&_canChangeBuffer }; # Boolean
+    public property streamOut => prop_get | owner_set; # stream
+    public property streamBody => {get => \&getStreamBody }; # stream
+    public property isHeaderPrinted => prop_get | owner_set; # Boolean 
+    
+    private property _bufferBody => prop_all;
+    private property _streamBody => prop_all;
 }
 
 __PACKAGE__->PassThroughArgs;
 
 our %CTOR = (
-	'IMPL::Object::Autofill' => sub {
-		my %args = @_;
-		
-		$args{query} = CGI->new($args{query} || {});
-		
-		%args;
-	}
+    'IMPL::Object::Autofill' => sub {
+        my %args = @_;
+        
+        $args{query} = CGI->new($args{query} || {});
+        
+        %args;
+    }
 );
 
 sub CTOR {
-	my ($this,%args) = @_;
-	
-	if (lc $this->streamOut eq 'memory') {
-		my $dummy = '';
-		open my $hout, '>:encoding(utf8)', \$dummy or die new IMPL::Exception("Failed to create memory stream",$!);
-		$this->streamOut($hout);
-	} elsif (not $this->streamOut) {
-		$this->streamOut(*STDOUT);	
-	} else {
-		die new IMPL::InvalidArgumentException("Invalid parameter value",$this->streamOut);
-	}
-	
-	$this->buffered(1) unless defined $this->buffered;
-	binmode $this->streamOut, ":encoding(".$this->charset.")";
+    my ($this,%args) = @_;
+    
+    if (lc $this->streamOut eq 'memory') {
+        my $dummy = '';
+        open my $hout, '>:encoding(utf8)', \$dummy or die new IMPL::Exception("Failed to create memory stream",$!);
+        $this->streamOut($hout);
+    } elsif (not $this->streamOut) {
+        $this->streamOut(*STDOUT);    
+    } else {
+        die new IMPL::InvalidArgumentException("Invalid parameter value",$this->streamOut);
+    }
+    
+    $this->buffered(1) unless defined $this->buffered;
+    binmode $this->streamOut, ":encoding(".$this->charset.")";
 }
 
 sub _checkHeaderPrinted {
-	my ($this,$value) = @_;
-	
-	die new IMPL::InvalidOperationException() if $this->isHeaderPrinted;
+    my ($this,$value) = @_;
+    
+    die new IMPL::InvalidOperationException() if $this->isHeaderPrinted;
 }
 
 sub _canChangeBuffer {
-	my ($this,$value) = @_;
-	
-	die new IMPL::InvalidOperationException() if $this->isHeaderPrinted or $this->_streamBody;
+    my ($this,$value) = @_;
+    
+    die new IMPL::InvalidOperationException() if $this->isHeaderPrinted or $this->_streamBody;
 }
 
 sub _charset {
-	my $this = shift;
-	
-	if (@_) {
-		my $charset = $this->query->charset(@_);
-		
-		my $hout = $this->streamOut;
-		
-		binmode $hout;
-		binmode $hout, ":encoding($charset)";
-		
-		return $charset;
-	} else {
-		return $this->query->charset;
-	}
+    my $this = shift;
+    
+    if (@_) {
+        my $charset = $this->query->charset(@_);
+        
+        my $hout = $this->streamOut;
+        
+        binmode $hout;
+        binmode $hout, ":encoding($charset)";
+        
+        return $charset;
+    } else {
+        return $this->query->charset;
+    }
 }
 
 sub _PrintHeader {
-	my ($this) = @_;
-	
-	unless ($this->isHeaderPrinted) {
-		$this->isHeaderPrinted(1);
-		
-		my %opt;
-		
-		$opt{-type} = $this->contentType if $this->contentType;
-		$opt{-status} = $this->status if $this->status;
-		$opt{-expires} = $this->expires if $this->expires;
-		
-		my $refCookies = $this->cookies;
-		$opt{-cookie} = [map _createCookie($_,$refCookies->{$_}), keys %$refCookies] if $refCookies;
-		
-		my $hOut = $this->streamOut;
-		
-		print $hOut $this->query->header(
-			%opt
-		);
-	}
+    my ($this) = @_;
+    
+    unless ($this->isHeaderPrinted) {
+        $this->isHeaderPrinted(1);
+        
+        my %opt;
+        
+        $opt{-type} = $this->contentType if $this->contentType;
+        $opt{-status} = $this->status if $this->status;
+        $opt{-expires} = $this->expires if $this->expires;
+        
+        my $refCookies = $this->cookies;
+        $opt{-cookie} = [map _createCookie($_,$refCookies->{$_}), keys %$refCookies] if $refCookies;
+        
+        my $hOut = $this->streamOut;
+        
+        print $hOut $this->query->header(
+            %opt
+        );
+    }
 }
 
 sub _createCookie {
-	return UNIVERSAL::isa($_[1], 'CGI::Cookie') ? $_[1] : CGI::Cookie->new(-name => $_[0], -value => $_[1] );
+    return UNIVERSAL::isa($_[1], 'CGI::Cookie') ? $_[1] : CGI::Cookie->new(-name => $_[0], -value => $_[1] );
 }
 
 sub setCookie {
-	my ($this,$name,$value) = @_;
-	
-	unless ($this->cookies) {
-		$this->cookies({$name,$value});
-	} else {
-		$this->_checkHeaderPrinted(); 
-		$this->cookies->{$name} = $value;
-	}
-	return $value;
+    my ($this,$name,$value) = @_;
+    
+    unless ($this->cookies) {
+        $this->cookies({$name,$value});
+    } else {
+        $this->_checkHeaderPrinted(); 
+        $this->cookies->{$name} = $value;
+    }
+    return $value;
 }
 
 sub getStreamBody {
-	my ($this) = @_;
-	
-	return undef unless $this->streamOut;
-	
-	unless ($this->_streamBody) {
-		if ($this->buffered) {
-			my $buffer = "";
-			
-			$this->_bufferBody(\$buffer);
-				
-			open my $hBody, ">:encoding(utf-8)", \$buffer or die new IMPL::Exception("Failed to create buffer",$!);
-			
-			Encode::_utf8_on($buffer);
-				
-			$this->_streamBody($hBody);
-		} else {
-			$this->_PrintHeader();
-			$this->_streamBody($this->streamOut);
-		}
-	}
-		
-	return $this->_streamBody;
+    my ($this) = @_;
+    
+    return undef unless $this->streamOut;
+    
+    unless ($this->_streamBody) {
+        if ($this->buffered) {
+            my $buffer = "";
+            
+            $this->_bufferBody(\$buffer);
+                
+            open my $hBody, ">:encoding(utf-8)", \$buffer or die new IMPL::Exception("Failed to create buffer",$!);
+            
+            Encode::_utf8_on($buffer);
+                
+            $this->_streamBody($hBody);
+        } else {
+            $this->_PrintHeader();
+            $this->_streamBody($this->streamOut);
+        }
+    }
+        
+    return $this->_streamBody;
 }
 
 sub Complete {
-	my ($this) = @_;
-	
-	return 0 unless $this->streamOut;
-	
-	my $hOut = $this->streamOut;
-	
-	$this->_PrintHeader();
+    my ($this) = @_;
+    
+    return 0 unless $this->streamOut;
+    
+    my $hOut = $this->streamOut;
+    
+    $this->_PrintHeader();
 
-	close $this->_streamBody();
-	
-	if ($this->buffered) {
-		print $hOut ${$this->_bufferBody};	
-	}	
-	
-	$this->_bufferBody(undef);
-	$this->streamOut(undef);
-	
-	return 1;
+    close $this->_streamBody();
+    
+    if ($this->buffered) {
+        print $hOut ${$this->_bufferBody};    
+    }    
+    
+    $this->_bufferBody(undef);
+    $this->streamOut(undef);
+    
+    return 1;
 }
 
 sub Discard {
-	my ($this) = @_;
-	
-	carp "Discarding sent response" if $this->isHeaderPrinted;
-	
-	$this->_streamBody(undef);
-	$this->_bufferBody(undef);
-	$this->streamOut(undef);
+    my ($this) = @_;
+    
+    carp "Discarding sent response" if $this->isHeaderPrinted;
+    
+    $this->_streamBody(undef);
+    $this->_bufferBody(undef);
+    $this->streamOut(undef);
 }
 
 1;