annotate Lib/IMPL/require.pm @ 203:68a59c3358ff

Implemented templates selection mechanism
author sergey
date Wed, 25 Apr 2012 18:06:11 +0400
parents 6b1dda998839
children 891c04080658
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
197
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
1 package IMPL::require;
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
2 use Scalar::Util qw(set_prototype);
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
3
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
4 sub import {
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
5 my ($self, $aliases) = @_;
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
6
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
7 return unless $aliases;
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
8
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
9 die "A hash reference is required" unless ref $aliases eq 'HASH';
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
10
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
11 my $caller = $caller;
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
12
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
13 no strict 'refs';
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
14
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
15 while( my ($alias, $class) = each %$aliases ) {
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
16 (my $file = $class) =~ s/::|'/\//g;
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
17 require "$file.pm";
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
18
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
19 *{"${caller}::$alias"} = set_prototype(sub {
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
20 $class
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
21 }, '');
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
22 }
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
23 }
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
24
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
25 1;
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
26
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
27 __END__
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
28
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
29 =pod
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
30
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
31 =head1 NAME
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
32
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
33 C<IMPL::require> загружает и назначет псевдонимы модулям.
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
34
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
35 =head1 SYNOPSIS
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
36
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
37 =begin code
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
38
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
39 use IMPL::require {
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
40 TFoo => 'My::Nested::Package::Foo',
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
41 FS => 'File::Spec'
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
42 };
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
43
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
44 my $obj = My::Nested::Package::Foo->new('foo');
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
45 $obj = TFoo->new('foo'); # ditto
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
46
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
47 FS->catdir('one','two','three');
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
48
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
49 =end code
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
50
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
51 =head1 DESCRIPTION
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
52
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
53 Загружает модули с помощью C<require> и создает константы которые возвращаю полное имя модуля.
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
54
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
55
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
56 =cut