diff Lib/IMPL/Web/View/TTControl.pm @ 241:f48a1a9f4fa2

+Added ViewResult to allow implementation of the view environment. *TTDocuments now storing creation parameters *TTControls automatically propagating layout and title meta to their attributes +Added UnauthorizaedException web exception *minor fixes
author sergey
date Thu, 18 Oct 2012 04:49:55 +0400
parents b8c724f6de36
children 6b6d4b2275a1
line wrap: on
line diff
--- a/Lib/IMPL/Web/View/TTControl.pm	Wed Oct 17 17:41:29 2012 +0400
+++ b/Lib/IMPL/Web/View/TTControl.pm	Thu Oct 18 04:49:55 2012 +0400
@@ -2,6 +2,8 @@
 use strict;
 
 use IMPL::Const qw(:prop);
+use IMPL::lang qw(:hash);
+use Scalar::Util qw(blessed);
 use IMPL::declare {
 	require => {
         TTContext => 'Template::Context',
@@ -10,7 +12,7 @@
         OperationException => '-IMPL::InvalidOperationException'
 	},
 	base => [
-	   'IMPL::Object' => '@_'
+	   'IMPL::Object' => undef
 	],
 	props => [
 	   id => PROP_RO,
@@ -30,6 +32,7 @@
 }
 
 our $AutoloadRegex = qr/^[a-z]/;
+our @REFLECT_META = qw(title layout);
 
 sub CTOR {
     my ($this,$name,$template,$context,$refProps) = @_;
@@ -44,11 +47,20 @@
     $this->name($name);
     $this->attributes({});
     
-    if (ref $refProps eq 'HASH') {
-        while (my($key,$value) = each %$refProps) {
-            $this->SetAttribute($key,$value);
+    my %attrs;
+    
+    foreach my $meta ( @REFLECT_META ) {
+        next if $meta =~ /^_/;
+        if( my $value = $template->$meta() ) {
+            $attrs{$meta} = $value;
         }
     }
+    
+    hashApply(\%attrs,$refProps) if ref $refProps eq 'HASH';
+    
+    while (my($key,$value) = each %attrs) {
+        $this->SetAttribute($key,$value);
+    }
 }
 
 sub InitInstance {
@@ -94,7 +106,7 @@
     $args = {} unless ref $args eq 'HASH';
     
     if(my $body = $this->GetRenderBlock ) {
-        return $this->context->include( $body, { %$args, this => $this, template => $this->template, document => $this->document } );
+        return $this->context->include( $body, { %$args, this => $this, template => $this->template } );
     } else {
         return "";
     }    
@@ -109,6 +121,8 @@
     
     if ($method =~ /$AutoloadRegex/) {
         my $this = shift;
+        
+        die OperationException->new("can't invoke method '$method' on an unblessed reference") unless blessed $this;
     
         return @_ ? $this->SetAttribute($method,@_) : $this->GetAttribute($method);
     } else {