Mercurial > pub > Impl
comparison Lib/IMPL/Web/Handler/TTView.pm @ 266:89179bb8c388
*corrected TTView to handle plain (and undefined) values
*added URL generating methods to Application::Action
*fixed the compare validatior for schemas
| author | cin | 
|---|---|
| date | Mon, 14 Jan 2013 03:10:06 +0400 | 
| parents | 32aceba4ee6d | 
| children | a8dbddf491dd | 
   comparison
  equal
  deleted
  inserted
  replaced
| 265:6b6d4b2275a1 | 266:89179bb8c388 | 
|---|---|
| 66 | 66 | 
| 67 my $doc = | 67 my $doc = | 
| 68 $this->loader->document( eval { $view->template } || $this->SelectView( $action, ref $model ), | 68 $this->loader->document( eval { $view->template } || $this->SelectView( $action, ref $model ), | 
| 69 $vars ); | 69 $vars ); | 
| 70 | 70 | 
| 71 $doc->location($view->location); | 71 $doc->location($action->context->{resourceLocation}); | 
| 72 | 72 | 
| 73 my %responseParams = ( | 73 my %responseParams = ( | 
| 74 type => $this->contentType, | 74 type => $this->contentType, | 
| 75 charset => $this->contentCharset, | 75 charset => $this->contentCharset, | 
| 76 body => $doc->Render() | 76 body => $doc->Render() | 
| 87 | 87 | 
| 88 sub SelectView { | 88 sub SelectView { | 
| 89 my ( $this, $action, $class ) = @_; | 89 my ( $this, $action, $class ) = @_; | 
| 90 | 90 | 
| 91 my @path = split /\//, $action->query->path_info(), -1; | 91 my @path = split /\//, $action->query->path_info(), -1; | 
| 92 | 92 | 
| 93 shift @path; # remove always empty leading segment | 93 shift @path; # remove always empty leading segment | 
| 94 | |
| 95 my $last = pop @path; | |
| 96 $last =~ s/\.\w+$//; | |
| 97 $last ||= $this->indexResource; | |
| 98 push @path, $last; | |
| 99 | 94 | 
| 100 $this->BuildCache unless $this->_selectorsCache; | 95 $this->BuildCache unless $this->_selectorsCache; | 
| 101 my $cache = $this->_selectorsCache; | 96 my $cache = $this->_selectorsCache; | 
| 102 | 97 | 
| 103 @path = reverse @path; | 98 @path = reverse @path; | 
| 104 | 99 | 
| 105 foreach | 100 foreach | 
| 106 my $subclass ( $class ? ( _GetHierarchy($class), '-default' ) : '-plain' ) | 101 my $subclass ( $class ? ( _GetHierarchy($class), '-default' ) : '-default' ) | 
| 107 { | 102 { | 
| 108 my @results; | 103 my @results; | 
| 109 push @results, | 104 push @results, | 
| 110 { result => $this->_classTemplates->{$subclass}, level => 0 } | 105 { result => $this->_classTemplates->{$subclass}, level => 0 } | 
| 111 if $this->_classTemplates->{$subclass}; | 106 if $this->_classTemplates->{$subclass}; | 
| 107 | |
| 112 if ( $cache->{$subclass} ) { | 108 if ( $cache->{$subclass} ) { | 
| 113 my $alternatives = | 109 my $alternatives = | 
| 114 [ { selector => $cache->{$subclass}, immediate => 1 } ]; | 110 [ { selector => $cache->{$subclass}, immediate => 1 } ]; | 
| 115 $alternatives = | 111 $alternatives = | 
| 116 $this->MatchAlternatives( $_, $alternatives, \@results ) | 112 $this->MatchAlternatives( $_, $alternatives, \@results ) | 
| 188 | 184 | 
| 189 sub MatchAlternatives { | 185 sub MatchAlternatives { | 
| 190 my ( $this, $segment, $alternatives, $results ) = @_; | 186 my ( $this, $segment, $alternatives, $results ) = @_; | 
| 191 | 187 | 
| 192 my @next; | 188 my @next; | 
| 193 | 189 | 
| 194 foreach my $alt (@$alternatives) { | 190 foreach my $alt (@$alternatives) { | 
| 195 while ( my ( $selector, $match ) = each %{ $alt->{selector} } ) { | 191 while ( my ( $selector, $match ) = each %{ $alt->{selector} } ) { | 
| 196 | 192 | 
| 197 my $context = { | 193 my $context = { | 
| 198 vars => \%{ $alt->{vars} || {} }, | 194 vars => \%{ $alt->{vars} || {} }, | 
