comparison 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
comparison
equal deleted inserted replaced
196:a705e848dcc7 197:6b1dda998839
1 package IMPL::require;
2 use Scalar::Util qw(set_prototype);
3
4 sub import {
5 my ($self, $aliases) = @_;
6
7 return unless $aliases;
8
9 die "A hash reference is required" unless ref $aliases eq 'HASH';
10
11 my $caller = $caller;
12
13 no strict 'refs';
14
15 while( my ($alias, $class) = each %$aliases ) {
16 (my $file = $class) =~ s/::|'/\//g;
17 require "$file.pm";
18
19 *{"${caller}::$alias"} = set_prototype(sub {
20 $class
21 }, '');
22 }
23 }
24
25 1;
26
27 __END__
28
29 =pod
30
31 =head1 NAME
32
33 C<IMPL::require> загружает и назначет псевдонимы модулям.
34
35 =head1 SYNOPSIS
36
37 =begin code
38
39 use IMPL::require {
40 TFoo => 'My::Nested::Package::Foo',
41 FS => 'File::Spec'
42 };
43
44 my $obj = My::Nested::Package::Foo->new('foo');
45 $obj = TFoo->new('foo'); # ditto
46
47 FS->catdir('one','two','three');
48
49 =end code
50
51 =head1 DESCRIPTION
52
53 Загружает модули с помощью C<require> и создает константы которые возвращаю полное имя модуля.
54
55
56 =cut