diff Lib/IMPL/Web/View/TTContext.pm @ 370:cbf4febf0930

ObjectMeta, Tests, migrating to the new metadata model.
author sergey
date Tue, 10 Dec 2013 03:02:01 +0400
parents 833e663796c4
children d5c8b955bf8d
line wrap: on
line diff
--- a/Lib/IMPL/Web/View/TTContext.pm	Mon Dec 09 17:35:34 2013 +0400
+++ b/Lib/IMPL/Web/View/TTContext.pm	Tue Dec 10 03:02:01 2013 +0400
@@ -25,7 +25,6 @@
 	no strict 'refs';
 	# modules is a global (for the whole document) templates cache
 	# tt_cache is a local (for the current context only) templtes cache
-	# view is a special variable, which will be cloned and passed to the nested context
 	foreach my $prop (qw(
 	   root
 	   base
@@ -37,8 +36,10 @@
 	   includes
 	   modules
 	   aliases
+	   
 	   id
-	   view
+	   metadata
+	   model
 	)) {
 		my $t = $prop;
 		
@@ -140,7 +141,7 @@
 
 sub display_for {
 	my $this = shift;
-	my $model = shift;
+	my $path = shift;
 	my ($template, $args);
 	
 	if (ref $_[0] eq 'HASH') {
@@ -153,15 +154,11 @@
 	my $prefix = $this->prefix;
 	
 	my $info;
+	my $meta = $this->resolve_model($path,$args);
 	
-    if (not(($args and delete $args->{_no_resolve}) or ref $model)) {
-		$info = $this->resolve_model($model,$args);
-	} else {
-		$info = {
-			model => $model,
-			prefix => ""
-		};
-	}
+	$info->{prefix} = $prefix ? $prefix . '.' . $path : $path;
+	$info->{model} = $meta->model;
+	$info->{metadata} = $meta;
 	
 	$template ||= $info->{template};
 	$template = $template ? $this->find_template($template) : $this->find_template_for($info->{model});
@@ -228,11 +225,6 @@
 		unshift @includes, $this->base;
 	}
 	
-	my $view = $this->view;
-	$view = ref $view eq 'HASH' ? { %{$view} } : {};
-	
-	hashApply($view, delete $env->{view});
-	
 	my $out = eval {
 		$ctx->localise(
             hashApply(
@@ -251,8 +243,7 @@
 		            display_model => sub {
 		            	$ctx->display_model(@_);
 		            },
-		            tt_cache => {},
-		            view => $view
+		            tt_cache => {}
 				},
                 $env
             )
@@ -328,29 +319,31 @@
 }
 
 sub resolve_model {
-	my ($this,$prefix,$args) = @_;
+	my ($this,$prefix) = @_;
 	
 	die ArgException->new(prefix => "the prefix must be specified")
 	   unless defined $prefix;
 	
-
-	
-	if (my $res = $this->stash->get(['resolve', [$this,$prefix,$args]] ) ) {
-		return $res;
+	my $meta = $this->metadata;
+	foreach my $part (grep length($_), split(/\.|\[(\d+)\]/, $prefix)) {
+		last unless $meta;
+		if ($part =~ /^\d+$/) {
+			$meta = $meta->GetItem($part);
+		} else {
+			$meta = $meta->GetProperty($part);
+		}
 	}
 	
-	my @comp = map { $_, 0 } grep length($_), split(/\.|\[(\d+)\]/, $prefix);
-	
-	return {
-		model => $this->stash->get(['model',0,@comp]),
-		prefix => $this->prefix ? $this->prefix . ".$prefix" : $prefix
-	};
+	return $meta;
 }
 
 sub find_template_for {
-	my ($this,$model, $nothrow) = @_;
+	my ($this,$meta, $nothrow) = @_;
 	
-	my $type = typeof($model);
+	return $this->find_template($meta->template)
+		if ($meta->template);
+	
+	my $type = $meta->modelType;
 	
 	return $this->find_template('templates/plain') unless $type;
 	
@@ -374,12 +367,13 @@
             	$this->cache->Set($sclass,$template);
             	return $template;
             } 
-                
+            
+            #todo $meta->GetISA
             push @isa, @{"${sclass}::ISA"};
         }
 		
 	}
-	$this->throw(Template::Constants::ERROR_FILE, "can't find a template for the model " . typeof($model))
+	$this->throw(Template::Constants::ERROR_FILE, "can't find a template for the model $type")
 		unless $nothrow;
 
 	return;