Mercurial > pub > Impl
comparison Lib/IMPL/Web/View/TTControl.pm @ 194:4d0e1962161c
Replaced tabs with spaces
IMPL::Web::View - fixed document model, new features (control classes, document constructor parameters)
| author | cin |
|---|---|
| date | Tue, 10 Apr 2012 20:08:29 +0400 |
| parents | a9faf883cdce |
| children | 292226770180 |
comparison
equal
deleted
inserted
replaced
| 193:8e8401c0aea4 | 194:4d0e1962161c |
|---|---|
| 6 | 6 |
| 7 use Template::Context(); | 7 use Template::Context(); |
| 8 use Scalar::Util qw(weaken); | 8 use Scalar::Util qw(weaken); |
| 9 | 9 |
| 10 use parent qw( | 10 use parent qw( |
| 11 IMPL::DOM::Node | 11 IMPL::DOM::Node |
| 12 ); | 12 ); |
| 13 | 13 |
| 14 { | 14 { |
| 15 my $nextId = 1; | 15 my $nextId = 1; |
| 16 sub _GetNextId { | 16 sub _GetNextId { |
| 17 return $nextId++; | 17 return $nextId++; |
| 18 } | 18 } |
| 19 } | 19 } |
| 20 | 20 |
| 21 | 21 |
| 22 BEGIN { | 22 BEGIN { |
| 23 public _dom property id => PROP_ALL; | 23 public _dom property id => PROP_ALL; |
| 24 | 24 |
| 25 public property context => PROP_GET | PROP_OWNERSET; | 25 public property context => PROP_GET | PROP_OWNERSET; |
| 26 public property template => PROP_ALL; | 26 public property template => PROP_ALL; |
| 27 } | 27 } |
| 28 | 28 |
| 29 | 29 |
| 30 sub CTOR { | 30 sub CTOR { |
| 31 my ($this,$name,$template,$context,$refProps) = @_; | 31 my ($this,$name,$template,$context,$refProps) = @_; |
| 32 | 32 |
| 33 $name ||= "control"; | 33 $name ||= "control"; |
| 34 | 34 |
| 35 $this->template( $template ) or die new IMPL::ArgumentException("A template is required"); | 35 $this->template( $template ) or die new IMPL::ArgumentException("A template is required"); |
| 36 $this->context( $context ) or die new IMPL::ArgumentException("A context is required"); | 36 $this->context( $context ) or die new IMPL::ArgumentException("A context is required"); |
| 37 | 37 |
| 38 $this->id($name . "-" . _GetNextId()) unless $this->id; | 38 $this->id($name . "-" . _GetNextId()) unless $this->id; |
| 39 | 39 |
| 40 weaken($this); # prevent cyclic references produces by the code below | 40 weaken($this); # prevent cyclic references produces by the code below |
| 41 | 41 |
| 42 $context->stash->set('append', sub { $this->appendChild(@_); undef; } ); | 42 $context->stash->set('append', sub { $this->appendChild(@_); undef; } ); |
| 43 $context->stash->set('select', sub { $this->selectNodes(@_); } ); | 43 $context->stash->set('select', sub { $this->selectNodes(@_); } ); |
| 44 | 44 |
| 45 } | 45 } |
| 46 | 46 |
| 47 our %CTOR = ( | 47 our %CTOR = ( |
| 48 'IMPL::DOM::Node' => sub { | 48 'IMPL::DOM::Node' => sub { |
| 49 nodeName => $_[0], | 49 nodeName => $_[0], |
| 50 %{ $_[3] || {} } | 50 %{ $_[3] || {} } |
| 51 } | 51 } |
| 52 ); | 52 ); |
| 53 | 53 |
| 54 sub InitInstance { | 54 sub InitInstance { |
| 55 my ($this,$args) = @_; | 55 my ($this,$args) = @_; |
| 56 | 56 |
| 57 $args ||= {}; | 57 $args ||= {}; |
| 58 | 58 |
| 59 if ( my $ctor = $this->template->blocks->{CTOR} ) { | 59 if ( my $ctor = $this->template->blocks->{CTOR} ) { |
| 60 $this->context->process($ctor, { %$args, this => $this } ); | 60 $this->context->include($ctor, { %$args, this => $this } ); |
| 61 $this->context->stash->set('this',undef); | 61 } |
| 62 } | |
| 63 } | 62 } |
| 64 | 63 |
| 65 sub renderBlock { | 64 sub renderBlock { |
| 66 $_[0]->template->blocks->{RENDER} || $_[0]->template; | 65 $_[0]->template->blocks->{RENDER} || $_[0]->template; |
| 67 } | 66 } |
| 68 | 67 |
| 69 sub Render { | 68 sub Render { |
| 70 my ($this,$args) = @_; | 69 my ($this,$args) = @_; |
| 71 | 70 |
| 72 $args = {} unless ref $args eq 'HASH'; | 71 $args = {} unless ref $args eq 'HASH'; |
| 73 | 72 |
| 74 if(my $body = $this->renderBlock ) { | 73 if(my $body = $this->renderBlock ) { |
| 75 return $this->context->include( $body, { %$args, this => $this, template => $this->template, document => $this->document } ); | 74 return $this->context->include( $body, { %$args, this => $this, template => $this->template, document => $this->document } ); |
| 76 } else { | 75 } else { |
| 77 return ""; | 76 return ""; |
| 78 } | 77 } |
| 79 } | 78 } |
| 80 | 79 |
| 81 sub AUTOLOAD { | 80 sub AUTOLOAD { |
| 82 our $AUTOLOAD; | 81 our $AUTOLOAD; |
| 83 | 82 |
| 84 my $method = ($AUTOLOAD =~ m/(\w+)$/)[0]; | 83 my $method = ($AUTOLOAD =~ m/(\w+)$/)[0]; |
| 85 | 84 |
| 86 return if $method eq 'DESTROY'; | 85 return if $method eq 'DESTROY'; |
| 87 | 86 |
| 88 my $this = shift; | 87 my $this = shift; |
| 89 | 88 |
| 90 $this->nodeProperty($method,@_); | 89 $this->nodeProperty($method,@_); |
| 91 } | 90 } |
| 92 | 91 |
| 93 1; | 92 1; |
| 94 | 93 |
| 95 __END__ | 94 __END__ |
