Mercurial > pub > Impl
diff Lib/IMPL/Web/View/TTControl.pm @ 238:b8c724f6de36
DOM model refactoring
TT view refactoring, controls are no longer derived from DOM nodes
bugfixes
author | sergey |
---|---|
date | Tue, 16 Oct 2012 01:33:06 +0400 |
parents | 2904da230022 |
children | f48a1a9f4fa2 |
line wrap: on
line diff
--- a/Lib/IMPL/Web/View/TTControl.pm Mon Oct 15 17:39:12 2012 +0400 +++ b/Lib/IMPL/Web/View/TTControl.pm Tue Oct 16 01:33:06 2012 +0400 @@ -1,23 +1,21 @@ package IMPL::Web::View::TTControl; use strict; -use Scalar::Util qw(weaken); - use IMPL::Const qw(:prop); use IMPL::declare { require => { TTContext => 'Template::Context', Exception => 'IMPL::Exception', - ArgumentException => '-IMPL::InvalidArgumentException' + ArgumentException => '-IMPL::InvalidArgumentException', + OperationException => '-IMPL::InvalidOperationException' }, base => [ - 'IMPL::DOM::Node' => sub { - nodeName => $_[0], - %{ $_[3] || {} } - } + 'IMPL::Object' => '@_' ], props => [ id => PROP_RO, + attributes => PROP_RW, + name => PROP_RO, context => PROP_RO, template => PROP_RO ] @@ -31,6 +29,8 @@ } } +our $AutoloadRegex = qr/^[a-z]/; + sub CTOR { my ($this,$name,$template,$context,$refProps) = @_; @@ -41,11 +41,14 @@ $this->id($name . "-" . _GetNextId()) unless $this->id; - #TODO: deprecated, cleanup - #weaken($this); # prevent cyclic references produced by the code below + $this->name($name); + $this->attributes({}); - #$context->stash->set('append', sub { $this->appendChild(@_); undef; } ); - #$context->stash->set('select', sub { $this->selectNodes(@_); } ); + if (ref $refProps eq 'HASH') { + while (my($key,$value) = each %$refProps) { + $this->SetAttribute($key,$value); + } + } } sub InitInstance { @@ -58,6 +61,29 @@ } } +sub GetAttribute { + my ($this,$name) = (shift,shift); + + if (my $method = $this->can($name)) { + unshift @_,$this; + goto &$method; + } else { + return $this->attributes->{$name}; + } +} + +sub SetAttribute { + my $this = shift; + my $name = shift; + + if (my $method = $this->can($name)) { + unshift @_, $this; + goto &$method; + } else { + return $this->attributes->{$name} = shift; + } +} + sub GetRenderBlock { $_[0]->template->blocks->{RENDER} || $_[0]->template; } @@ -81,9 +107,13 @@ return if $method eq 'DESTROY'; - my $this = shift; - - $this->nodeProperty($method,@_); + if ($method =~ /$AutoloadRegex/) { + my $this = shift; + + return @_ ? $this->SetAttribute($method,@_) : $this->GetAttribute($method); + } else { + die OperationException->new("The specified method '$method' doesn't exists"); + } } 1;