Mercurial > pub > Impl
view Lib/IMPL/Web/View/TTControl.pm @ 354:9330835535b9
fixed view double rendering
author | cin |
---|---|
date | Wed, 16 Oct 2013 17:28:40 +0400 |
parents | feeb3bc4a818 |
children | 97131d500f16 |
line wrap: on
line source
package IMPL::Web::View::TTControl; use strict; use IMPL::Const qw(:prop); use IMPL::lang qw(:hash :base); use IMPL::declare { require => { Exception => 'IMPL::Exception', ArgException => '-IMPL::InvalidArgumentException' }, base => [ 'IMPL::Object' => undef ], props => [ context => PROP_RO, template => PROP_RO, id => { get => sub { shift->_stash->get('id') }, set => sub { shift->_stash->set('id',shift) } } ] }; { my $nextId = 1; sub _GetNextId { return '_' . $nextId++; } } our $AUTOLOAD_REGEX = qr/^[a-z]/; sub CTOR { my ($this,$context,$template) = @_; $this->context($context) or die ArgException->new(context => 'A context is required'); $this->template($template) or die ArgException->new(template => 'A template is required'); } sub _stash { $_[0]->context->stash; } sub Render { my ($this,$args) = @_; return $this->context->include($this->template,$args); } our $AUTOLOAD; sub AUTOLOAD { my ($prop) = ($AUTOLOAD =~ m/(\w+)$/); die Exception->new("Method not found: $AUTOLOAD") unless $prop=~/$AUTOLOAD_REGEX/ and $_[0]; no strict 'refs'; my $method = sub { my $that = shift; if (@_ == 0) { return $that->_stash->get($prop); } elsif (@_ == 1) { return $that->_stash->set($prop,shift); } else { return $that->_stash->get([$prop,[@_]]); } }; *{$AUTOLOAD} = $method; goto &$method; } 1; __END__ =pod =head1 NAME C<IMPL::Web::View::TTControl> расширяет функциональность шаблонов =head1 SYNPOSIS =begin code package My::View::Menu; use IMPL::declare { base => [ 'IMPL::Web::View::TTControl' => '@_' ] }; sub Render { my ($this,$args) = @_; $this->PrepareItems($args); return $this->next::method($args); } sub PrepareItems =end code =head1 DESCRIPTION =cut