view Lib/IMPL/Code/Loader.pm @ 241:f48a1a9f4fa2

+Added ViewResult to allow implementation of the view environment. *TTDocuments now storing creation parameters *TTControls automatically propagating layout and title meta to their attributes +Added UnauthorizaedException web exception *minor fixes
author sergey
date Thu, 18 Oct 2012 04:49:55 +0400
parents 6d8092d8ce1b
children 8d36073411b1
line wrap: on
line source

package IMPL::Code::Loader;
use strict;
use warnings;

use IMPL::Const qw(:prop);

use IMPL::declare {
	require => {
		Exception => 'IMPL::Exception',
		ArgumentException => '-IMPL::InvalidArgumentException' 
	},
	base => {
		'IMPL::Object' => undef,
		'IMPL::Object::Autofill' => '@_'
	},
	props => [
	   verifyNames => PROP_RO,
	   prefix => PROP_RO,
	   _pending => PROP_RW
	]
};

my $default;
sub default {
	$default ||= new IMPL::Code::Loader;
}

my $safe;
sub safe {
	$safe ||= new IMPL::Code::Loader(verifyNames => 1);
}

sub CTOR {
    my ($this) = @_;
    
    $this->_pending({});
}

sub Require {
    my ($this,$package) = @_;
    
    if ($this->verifyNames) {
    	$package =~ m/^([a-zA-Z_0-9]+(?:::[a-zA-Z_0-9]+)*)$/
    	   or die ArgumentException->new(package => 'Invalid package name') ;
    }
    
    $package = $this->prefix . '::' . $package if $this->prefix;
    
    my $file = join('/', split(/::/,$package)) . ".pm";
    
    require $file;
        
    return $package;
}

sub GetFullName {
    my ($this,$package) = @_;
    
    if ($this->verifyNames) {
        $package =~ m/^([a-zA-Z_0-9]+(?:::[a-zA-Z_0-9]+)*)$/
           or die ArgumentException->new(package => 'Invalid package name') ;
    }
    
    return $this->prefix . '::' . $package if $this->prefix;
}

1;