comparison 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
comparison
equal deleted inserted replaced
240:abc7c26bf615 241:f48a1a9f4fa2
1 package IMPL::Web::View::TTControl; 1 package IMPL::Web::View::TTControl;
2 use strict; 2 use strict;
3 3
4 use IMPL::Const qw(:prop); 4 use IMPL::Const qw(:prop);
5 use IMPL::lang qw(:hash);
6 use Scalar::Util qw(blessed);
5 use IMPL::declare { 7 use IMPL::declare {
6 require => { 8 require => {
7 TTContext => 'Template::Context', 9 TTContext => 'Template::Context',
8 Exception => 'IMPL::Exception', 10 Exception => 'IMPL::Exception',
9 ArgumentException => '-IMPL::InvalidArgumentException', 11 ArgumentException => '-IMPL::InvalidArgumentException',
10 OperationException => '-IMPL::InvalidOperationException' 12 OperationException => '-IMPL::InvalidOperationException'
11 }, 13 },
12 base => [ 14 base => [
13 'IMPL::Object' => '@_' 15 'IMPL::Object' => undef
14 ], 16 ],
15 props => [ 17 props => [
16 id => PROP_RO, 18 id => PROP_RO,
17 attributes => PROP_RW, 19 attributes => PROP_RW,
18 name => PROP_RO, 20 name => PROP_RO,
28 return $nextId++; 30 return $nextId++;
29 } 31 }
30 } 32 }
31 33
32 our $AutoloadRegex = qr/^[a-z]/; 34 our $AutoloadRegex = qr/^[a-z]/;
35 our @REFLECT_META = qw(title layout);
33 36
34 sub CTOR { 37 sub CTOR {
35 my ($this,$name,$template,$context,$refProps) = @_; 38 my ($this,$name,$template,$context,$refProps) = @_;
36 39
37 $name ||= "control"; 40 $name ||= "control";
42 $this->id($name . "-" . _GetNextId()) unless $this->id; 45 $this->id($name . "-" . _GetNextId()) unless $this->id;
43 46
44 $this->name($name); 47 $this->name($name);
45 $this->attributes({}); 48 $this->attributes({});
46 49
47 if (ref $refProps eq 'HASH') { 50 my %attrs;
48 while (my($key,$value) = each %$refProps) { 51
49 $this->SetAttribute($key,$value); 52 foreach my $meta ( @REFLECT_META ) {
53 next if $meta =~ /^_/;
54 if( my $value = $template->$meta() ) {
55 $attrs{$meta} = $value;
50 } 56 }
57 }
58
59 hashApply(\%attrs,$refProps) if ref $refProps eq 'HASH';
60
61 while (my($key,$value) = each %attrs) {
62 $this->SetAttribute($key,$value);
51 } 63 }
52 } 64 }
53 65
54 sub InitInstance { 66 sub InitInstance {
55 my ($this,$args) = @_; 67 my ($this,$args) = @_;
92 my ($this,$args) = @_; 104 my ($this,$args) = @_;
93 105
94 $args = {} unless ref $args eq 'HASH'; 106 $args = {} unless ref $args eq 'HASH';
95 107
96 if(my $body = $this->GetRenderBlock ) { 108 if(my $body = $this->GetRenderBlock ) {
97 return $this->context->include( $body, { %$args, this => $this, template => $this->template, document => $this->document } ); 109 return $this->context->include( $body, { %$args, this => $this, template => $this->template } );
98 } else { 110 } else {
99 return ""; 111 return "";
100 } 112 }
101 } 113 }
102 114
107 119
108 return if $method eq 'DESTROY'; 120 return if $method eq 'DESTROY';
109 121
110 if ($method =~ /$AutoloadRegex/) { 122 if ($method =~ /$AutoloadRegex/) {
111 my $this = shift; 123 my $this = shift;
124
125 die OperationException->new("can't invoke method '$method' on an unblessed reference") unless blessed $this;
112 126
113 return @_ ? $this->SetAttribute($method,@_) : $this->GetAttribute($method); 127 return @_ ? $this->SetAttribute($method,@_) : $this->GetAttribute($method);
114 } else { 128 } else {
115 die OperationException->new("The specified method '$method' doesn't exists"); 129 die OperationException->new("The specified method '$method' doesn't exists");
116 } 130 }