view Lib/IMPL/require.pm @ 197:6b1dda998839

Added IMPL::declare, IMPL::require, to simplify module definitions IMPL::Transform now admires object inheritance while searching for the transformation Added HTTP some exceptions IMPL::Web::Application::RestResource almost implemented
author sergey
date Thu, 19 Apr 2012 02:10:02 +0400
parents
children 891c04080658
line wrap: on
line source

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

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 ) {
		(my $file = $class) =~ s/::|'/\//g;
		require "$file.pm";
		
		*{"${caller}::$alias"} = set_prototype(sub {
            $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