Mercurial > pub > Impl
annotate Lib/IMPL/Code/Loader.pm @ 234:2530d1bb9638
sync
author | sergey |
---|---|
date | Thu, 11 Oct 2012 20:11:45 +0400 |
parents | 6d8092d8ce1b |
children | 8d36073411b1 |
rev | line source |
---|---|
165 | 1 package IMPL::Code::Loader; |
2 use strict; | |
3 use warnings; | |
4 | |
230 | 5 use IMPL::Const qw(:prop); |
209 | 6 |
7 use IMPL::declare { | |
8 require => { | |
9 Exception => 'IMPL::Exception', | |
10 ArgumentException => '-IMPL::InvalidArgumentException' | |
11 }, | |
12 base => { | |
13 'IMPL::Object' => undef, | |
14 'IMPL::Object::Autofill' => '@_' | |
230 | 15 }, |
16 props => [ | |
17 verifyNames => PROP_RO, | |
18 prefix => PROP_RO, | |
19 _pending => PROP_RW | |
20 ] | |
209 | 21 }; |
165 | 22 |
209 | 23 my $default; |
24 sub default { | |
25 $default ||= new IMPL::Code::Loader; | |
165 | 26 } |
27 | |
209 | 28 my $safe; |
29 sub safe { | |
30 $safe ||= new IMPL::Code::Loader(verifyNames => 1); | |
31 } | |
32 | |
230 | 33 sub CTOR { |
34 my ($this) = @_; | |
35 | |
36 $this->_pending({}); | |
209 | 37 } |
38 | |
165 | 39 sub Require { |
209 | 40 my ($this,$package) = @_; |
194 | 41 |
209 | 42 if ($this->verifyNames) { |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
209
diff
changeset
|
43 $package =~ m/^([a-zA-Z_0-9]+(?:::[a-zA-Z_0-9]+)*)$/ |
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
209
diff
changeset
|
44 or die ArgumentException->new(package => 'Invalid package name') ; |
209 | 45 } |
194 | 46 |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
209
diff
changeset
|
47 $package = $this->prefix . '::' . $package if $this->prefix; |
194 | 48 |
209 | 49 my $file = join('/', split(/::/,$package)) . ".pm"; |
194 | 50 |
209 | 51 require $file; |
230 | 52 |
53 return $package; | |
54 } | |
55 | |
56 sub GetFullName { | |
57 my ($this,$package) = @_; | |
58 | |
59 if ($this->verifyNames) { | |
60 $package =~ m/^([a-zA-Z_0-9]+(?:::[a-zA-Z_0-9]+)*)$/ | |
61 or die ArgumentException->new(package => 'Invalid package name') ; | |
62 } | |
63 | |
64 return $this->prefix . '::' . $package if $this->prefix; | |
165 | 65 } |
66 | |
67 1; | |
68 |