view Lib/IMPL/Web/View/TTRegistry.pm @ 309:5e4e7c8fbca1

sync
author cin
date Fri, 19 Apr 2013 00:27:51 +0400
parents b5d5793f348e
children 72799d1211c5
line wrap: on
line source

package IMPL::Web::View::TTRegistry;
use strict;
use mro;

use IMPL::Const qw(:prop);
use IMPL::declare {
    require => {
        TTFactory => 'IMPL::Web::View::TTFactory',
        TTControl => '-IMPL::Web::View::TTControl'
    },
    base => [
        'IMPL::Object' => undef,
        'IMPL::Object::Disposable' => undef
    ],
    props => [
        loader => PROP_RW,
        context => PROP_RW,
        _cache => PROP_RW,
    ]
};

sub CTOR {
	my ($this,$loader,$context) = @_;
	
	$this->loader($loader);
	$this->context($context);
	$this->_cache({});
}

sub Require {
    my ($this,$name) = @_;
    
    if(my $factory = $this->_cache->{$name}) {
        return $factory;
    } else {
        my $template = $this->loader->template($name)
            or die AppException->new("Failed to load a template $name");
         
        $factory = TTFactory->new(
            $template->class || TTControl,
            $template,
            $this->context,
            $name,
            $this
        );
        
        $this->_cache->{$name} = $factory;
        return $factory;
    }
}

sub Dispose {
	my ($this) = @_;
	
	$this->_cache(undef);
	$this->context(undef);
	$this->loader(undef);
	
	$this->next::method();
}

1;

__END__

=pod

=head1 NAME

C<IMPL::Web::View::Registry> - реестр шаблонов документа.

=head1 DESCRIPTION

Используется для реализации функции C<require> внутри шаблонов.



=cut