Mercurial > pub > Impl
diff Lib/IMPL/Web/TT/Document.pm @ 117:0475eb382085
Controls support (RC1)
author | wizard |
---|---|
date | Thu, 03 Jun 2010 02:41:44 +0400 |
parents | ddf0f037d460 |
children | 92c850d0bdb9 |
line wrap: on
line diff
--- a/Lib/IMPL/Web/TT/Document.pm Mon May 31 08:30:39 2010 +0400 +++ b/Lib/IMPL/Web/TT/Document.pm Thu Jun 03 02:41:44 2010 +0400 @@ -90,7 +90,7 @@ die new IMPL::InvalidArgumentException("A controlClass must be a single word",$controlClass) unless $controlClass =~ /^\w+$/; - eval "require $type; 1;" or die new IMPL::Exception("Failed to load a module",$type,"$@") unless ref $type or $INC{$type}; + eval "require $type; 1;" or die new IMPL::Exception("Failed to load a module",$type,"$@") unless eval { $type->can('new') }; die new IMPL::InvalidArgumentException("A type must be subclass of IMPL::DOM::Node",$type) unless $type->isa('IMPL::DOM::Node'); @@ -101,6 +101,33 @@ }; } +sub require { + my ($this,$template) = @_; + + my $doc = $this->context->template($template); + + die new IMPL::InvalidOperationException("A specified template isn't a document",$template) unless eval{ $doc -> isa('Template::Document') }; + + my $controlClass = $doc->class; + my $type = $doc->nativeType; + my $controlTemplate; + my $out = ""; + + die new IMPL::InvalidOperationException("A specified template isn't a control",$template) unless $controlClass; + + if (not $this->isControlClass($controlClass)) { + if ($doc->template) { + $controlTemplate = $doc->blocks()->{$doc->template} || $this->context->template($doc->template); + $out = $this->context->process($doc); + } else { + $controlTemplate = $doc; + } + $this->registerControlClass($controlClass,$type,{ template => $controlTemplate } ); + } + + return $out; +} + sub isControlClass { my ($this,$name) = @_; return $this->_controlClassMap->{$name} ? 1 : 0;