annotate Lib/IMPL/require.pm @ 232:5c82eec23bb6

Fixed degradations due refactoring
author sergey
date Tue, 09 Oct 2012 20:12:47 +0400
parents 6d8092d8ce1b
children b8c724f6de36
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);
205
891c04080658 IMPL::Web::View fixed template selection, release candidate
sergey
parents: 197
diff changeset
3 use strict;
230
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 205
diff changeset
4 require IMPL::Code::Loader;
197
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
5
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
6 sub import {
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
7 my ($self, $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 return unless $aliases;
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 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
12
205
891c04080658 IMPL::Web::View fixed template selection, release candidate
sergey
parents: 197
diff changeset
13 my $caller = caller;
197
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 no strict 'refs';
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
16
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
17 while( my ($alias, $class) = each %$aliases ) {
230
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 205
diff changeset
18 _require($class);
197
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
19
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
20 *{"${caller}::$alias"} = set_prototype(sub {
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
21 $class
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
230
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 205
diff changeset
26 sub _require {
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 205
diff changeset
27 my ($class) = @_;
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 205
diff changeset
28
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 205
diff changeset
29 if ( not $class =~ s/^-// ) {
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 205
diff changeset
30 ( my $file = $class ) =~ s/::|'/\//g;
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 205
diff changeset
31 require "$file.pm";
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 205
diff changeset
32 }
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 205
diff changeset
33 $class;
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 205
diff changeset
34 }
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 205
diff changeset
35
197
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
36 1;
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
37
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
38 __END__
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
39
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
40 =pod
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
41
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
42 =head1 NAME
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 C<IMPL::require> загружает и назначет псевдонимы модулям.
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
45
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
46 =head1 SYNOPSIS
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
47
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
48 =begin code
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
49
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
50 use IMPL::require {
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
51 TFoo => 'My::Nested::Package::Foo',
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
52 FS => 'File::Spec'
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
53 };
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 my $obj = My::Nested::Package::Foo->new('foo');
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
56 $obj = TFoo->new('foo'); # ditto
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
57
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
58 FS->catdir('one','two','three');
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
59
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
60 =end code
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
61
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
62 =head1 DESCRIPTION
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
63
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
64 Загружает модули с помощью C<require> и создает константы которые возвращаю полное имя модуля.
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
65
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
66
6b1dda998839 Added IMPL::declare, IMPL::require, to simplify module definitions
sergey
parents:
diff changeset
67 =cut