Mercurial > pub > Impl
comparison 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 |
comparison
equal
deleted
inserted
replaced
116:1722ca51537c | 117:0475eb382085 |
---|---|
88 | 88 |
89 $type ||= 'IMPL::Web::TT::Control'; | 89 $type ||= 'IMPL::Web::TT::Control'; |
90 | 90 |
91 die new IMPL::InvalidArgumentException("A controlClass must be a single word",$controlClass) unless $controlClass =~ /^\w+$/; | 91 die new IMPL::InvalidArgumentException("A controlClass must be a single word",$controlClass) unless $controlClass =~ /^\w+$/; |
92 | 92 |
93 eval "require $type; 1;" or die new IMPL::Exception("Failed to load a module",$type,"$@") unless ref $type or $INC{$type}; | 93 eval "require $type; 1;" or die new IMPL::Exception("Failed to load a module",$type,"$@") unless eval { $type->can('new') }; |
94 | 94 |
95 die new IMPL::InvalidArgumentException("A type must be subclass of IMPL::DOM::Node",$type) unless $type->isa('IMPL::DOM::Node'); | 95 die new IMPL::InvalidArgumentException("A type must be subclass of IMPL::DOM::Node",$type) unless $type->isa('IMPL::DOM::Node'); |
96 | 96 |
97 $this->_controlClassMap->{$controlClass} = { | 97 $this->_controlClassMap->{$controlClass} = { |
98 controlClass => $controlClass, | 98 controlClass => $controlClass, |
99 type => $type, | 99 type => $type, |
100 args => ref $args eq 'HASH' ? $args : {} | 100 args => ref $args eq 'HASH' ? $args : {} |
101 }; | 101 }; |
102 } | |
103 | |
104 sub require { | |
105 my ($this,$template) = @_; | |
106 | |
107 my $doc = $this->context->template($template); | |
108 | |
109 die new IMPL::InvalidOperationException("A specified template isn't a document",$template) unless eval{ $doc -> isa('Template::Document') }; | |
110 | |
111 my $controlClass = $doc->class; | |
112 my $type = $doc->nativeType; | |
113 my $controlTemplate; | |
114 my $out = ""; | |
115 | |
116 die new IMPL::InvalidOperationException("A specified template isn't a control",$template) unless $controlClass; | |
117 | |
118 if (not $this->isControlClass($controlClass)) { | |
119 if ($doc->template) { | |
120 $controlTemplate = $doc->blocks()->{$doc->template} || $this->context->template($doc->template); | |
121 $out = $this->context->process($doc); | |
122 } else { | |
123 $controlTemplate = $doc; | |
124 } | |
125 $this->registerControlClass($controlClass,$type,{ template => $controlTemplate } ); | |
126 } | |
127 | |
128 return $out; | |
102 } | 129 } |
103 | 130 |
104 sub isControlClass { | 131 sub isControlClass { |
105 my ($this,$name) = @_; | 132 my ($this,$name) = @_; |
106 return $this->_controlClassMap->{$name} ? 1 : 0; | 133 return $this->_controlClassMap->{$name} ? 1 : 0; |