diff Lib/IMPL/Web/QueryHandler/PageFormat.pm @ 154:eb478083f72b

Url support
author wizard
date Thu, 30 Sep 2010 02:13:05 +0400
parents 60fd224f3e3c
children 8638dd1374bf
line wrap: on
line diff
--- a/Lib/IMPL/Web/QueryHandler/PageFormat.pm	Mon Sep 27 19:15:34 2010 +0400
+++ b/Lib/IMPL/Web/QueryHandler/PageFormat.pm	Thu Sep 30 02:13:05 2010 +0400
@@ -11,6 +11,7 @@
 use IMPL::Security::Context;
 use File::Spec;
 use HTML::TreeBuilder;
+use URI;
 use Error qw(:try);
 
 $Template::Plugin::URL::JOINT = '&';
@@ -72,22 +73,26 @@
 		my @pathContainer = @path;
 		pop @pathContainer;
 		
-		$doc->LoadFile ( File::Spec->catfile($this->templatesBase,@path), $this->templatesCharset, $this->templatesBase );
-		
-		$doc->AddVar( result => $nextHandler->() );
-		$doc->AddVar( action => $action );
-		$doc->AddVar( app => $action->application );
+		$doc->LoadFile (
+			File::Spec->catfile($this->templatesBase,@path),
+			$this->templatesCharset,
+			$this->templatesBase,
+			{
+				result => scalar($nextHandler->()),
+				action => $action,
+				app => $action->application,
 		
-		$doc->AddVar( absoluteUrl => sub { join '/', @root, $_[0] } );
-		$doc->AddVar( baseUrl => sub { join '/', @root, @base, $_[0] } );
-		$doc->AddVar( relativeUrl => sub { join '/', @root, @base, @pathContainer,$_[0] } );
+				absoluteUrl => sub { new URI(join ('/', @root, $_[0]) ) },
+				baseUrl => sub { new URI (join ('/', @root, @base, $_[0]) ) },
+				relativeUrl => sub { new URI(join ('/', @root, @base, @pathContainer,$_[0]) ) },
 		
-		$doc->AddVar( user => IMPL::Security::Context->current->principal );
-		$doc->AddVar( session => IMPL::Security::Context->current );
+				user => IMPL::Security::Context->current->principal,
+				session => IMPL::Security::Context->current,
 		
-		$doc->AddVar( to_json => \&to_json );
-		$doc->AddVar( escape_string => sub { $_[0] =~ s/"/"/g; $_[0] } );
-		
+				to_json => \&to_json,
+				escape_string => sub { $_[0] =~ s/"/"/g; $_[0] },
+			}
+		);
 		
 		$action->response->contentType('text/html');
 		my $hOut = $action->response->streamBody;
@@ -110,6 +115,17 @@
 	};
 }
 
+sub URI::_query::new_params {
+	my ($this,$params) = @_;
+	
+	my $clone = $this->clone;
+	if (ref $params eq 'HASH' ) {
+		my %newParams = ($clone->query_form , %$params);
+		$clone->query_form(map { $_, $newParams{$_} } sort keys %newParams );
+	}
+	return $clone;
+}
+
 1;
 
 __END__