Mercurial > pub > Impl
comparison Lib/IMPL/require.pm @ 230:6d8092d8ce1b
*reworked IMPL::Security
*reworked IMPL::Web::Security
*refactoring
author | sergey |
---|---|
date | Mon, 08 Oct 2012 03:37:37 +0400 |
parents | 891c04080658 |
children | b8c724f6de36 |
comparison
equal
deleted
inserted
replaced
229:47f77e6409f7 | 230:6d8092d8ce1b |
---|---|
1 package IMPL::require; | 1 package IMPL::require; |
2 use Scalar::Util qw(set_prototype); | 2 use Scalar::Util qw(set_prototype); |
3 use strict; | 3 use strict; |
4 require IMPL::Code::Loader; | |
4 | 5 |
5 sub import { | 6 sub import { |
6 my ($self, $aliases) = @_; | 7 my ($self, $aliases) = @_; |
7 | 8 |
8 return unless $aliases; | 9 return unless $aliases; |
12 my $caller = caller; | 13 my $caller = caller; |
13 | 14 |
14 no strict 'refs'; | 15 no strict 'refs'; |
15 | 16 |
16 while( my ($alias, $class) = each %$aliases ) { | 17 while( my ($alias, $class) = each %$aliases ) { |
17 (my $file = $class) =~ s/::|'/\//g; | 18 _require($class); |
18 require "$file.pm"; | |
19 | 19 |
20 *{"${caller}::$alias"} = set_prototype(sub { | 20 *{"${caller}::$alias"} = set_prototype(sub { |
21 $class | 21 $class |
22 }, ''); | 22 }, ''); |
23 } | 23 } |
24 } | |
25 | |
26 sub _require { | |
27 my ($class) = @_; | |
28 | |
29 if ( not $class =~ s/^-// ) { | |
30 ( my $file = $class ) =~ s/::|'/\//g; | |
31 require "$file.pm"; | |
32 } | |
33 $class; | |
24 } | 34 } |
25 | 35 |
26 1; | 36 1; |
27 | 37 |
28 __END__ | 38 __END__ |