# HG changeset patch # User wizard # Date 1274058728 -14400 # Node ID ddf0f037d460a7654601dc57cbb3ac47c31d6744 # Parent c6fb6964de4c6b57d95d65a4ba6d332f56e7455b IMPL::DOM::Node updated to support TT, (added childNodesRef and selectNodesRef for using from TT) Some fixes to the web document model. (beta version) diff -r c6fb6964de4c -r ddf0f037d460 Lib/IMPL/DOM/Node.pm --- a/Lib/IMPL/DOM/Node.pm Fri May 14 16:06:06 2010 +0400 +++ b/Lib/IMPL/DOM/Node.pm Mon May 17 05:12:08 2010 +0400 @@ -96,6 +96,11 @@ return wantarray ? @{ $this->{$childNodes} } : $this->{$childNodes}; } +sub childNodesRef { + my ($this) = @_; + return scalar $this->_getChildNodes; +} + sub removeNode { my ($this,$node) = @_; @@ -197,6 +202,13 @@ return wantarray ? @set : \@set; } +sub selectNodesRef { + my $this = shift; + + my @result = $this->selectNodes(@_); + return \@result; +} + sub translatePath { my ($this,$path) = @_; diff -r c6fb6964de4c -r ddf0f037d460 Lib/IMPL/Web/TT/Collection.pm --- a/Lib/IMPL/Web/TT/Collection.pm Fri May 14 16:06:06 2010 +0400 +++ b/Lib/IMPL/Web/TT/Collection.pm Mon May 17 05:12:08 2010 +0400 @@ -10,10 +10,31 @@ my $this = shift; my ($method) = ($AUTOLOAD =~ /(\w+)$/); - my @result = $this->selectNodes($method); + return if $method eq 'DESTROY'; + + if ($method =~ /^add(\w+)/) { + my ($name,$args) = @_; + return $this->appendChild($this->document->CreateControl($name,$1,$args)); + } - return $result[0] if @result; - return; + if ( @_ >= 1 ) { + # set + # we can't assing a node, so this is a dynamic property + return $this->nodeProperty($method,@_); + } else { + # get + # try a dynamic property first + if ( my $val = $this->nodeProperty($method) ) { + return $val; + } else { + # and return a first child node as last opportunity + my @result = $this->selectNodes($method); + + return $result[0] if @result; + return; + } + } + die new IMPL::Exception("We shoud never get here, this is a bug!!!"); } sub as_list { diff -r c6fb6964de4c -r ddf0f037d460 Lib/IMPL/Web/TT/Control.pm --- a/Lib/IMPL/Web/TT/Control.pm Fri May 14 16:06:06 2010 +0400 +++ b/Lib/IMPL/Web/TT/Control.pm Mon May 17 05:12:08 2010 +0400 @@ -17,7 +17,12 @@ sub CTOR { my ($this,%args) = @_; + if ($this->document) { + # load a template + #$args{template} = $this->document->context->template($args{template}) if ($args{template}); + } $this->template($args{template}) if $args{template}; + $this->id($this->nodeName . '-' . $nextId++); $this->controlClass($args{controlClass} || 'Control'); } diff -r c6fb6964de4c -r ddf0f037d460 Lib/IMPL/Web/TT/Document.pm --- a/Lib/IMPL/Web/TT/Document.pm Fri May 14 16:06:06 2010 +0400 +++ b/Lib/IMPL/Web/TT/Document.pm Mon May 17 05:12:08 2010 +0400 @@ -10,6 +10,7 @@ use Scalar::Util qw(blessed); use IMPL::Web::TT::Collection; use IMPL::Web::TT::Control; +use Carp; BEGIN { private property _provider => prop_all; @@ -100,6 +101,11 @@ }; } +sub isControlClass { + my ($this,$name) = @_; + return $this->_controlClassMap->{$name} ? 1 : 0; +} + sub _getControls { my ($this) = @_; @@ -190,6 +196,7 @@ my @result = $this->selectNodes($method); return $result[0] if @result; + carp "Looks like you have a mistake, document doesn't have a such property or child: $method"; return; }