view Lib/IMPL/require.pm @ 245:7c517134c42f

Added Unsupported media type Web exception corrected resourceLocation setting in the resource Implemented localizable resources for text messages fixed TT view scopings, INIT block in controls now sets globals correctly.
author sergey
date Mon, 29 Oct 2012 03:15:22 +0400
parents b8c724f6de36
children 9f394b27dccf
line wrap: on
line source

package IMPL::require;
use Scalar::Util qw(set_prototype);
use strict;
require IMPL::Code::Loader;

sub import {
	my ($self, $aliases) = @_;
	
	return unless $aliases;
	
	die "A hash reference is required" unless ref $aliases eq 'HASH';
	
	my $caller = caller;
	
	no strict 'refs';
	
	while( my ($alias, $class) = each %$aliases ) {
	    $class = _require($class);
		
		*{"${caller}::$alias"} = set_prototype(sub {
            $class
        }, '');
	}
}

sub _require {
    my ($class) = @_;

    if ( not $class =~ s/^-// ) {
        ( my $file = $class ) =~ s/::|'/\//g;
        require "$file.pm";
    }
    $class;
}

1;

__END__

=pod

=head1 NAME

C<IMPL::require> загружает и назначет псевдонимы модулям.

=head1 SYNOPSIS

=begin code

use IMPL::require {
	TFoo => 'My::Nested::Package::Foo',
	FS => 'File::Spec'
};

my $obj = My::Nested::Package::Foo->new('foo');
$obj = TFoo->new('foo'); # ditto

FS->catdir('one','two','three');

=end code

=head1 DESCRIPTION

Загружает модули с помощью C<require> и создает константы которые возвращаю полное имя модуля.


=cut