Mercurial > pub > Impl
comparison Lib/IMPL/Code/Loader.pm @ 230:6d8092d8ce1b
*reworked IMPL::Security
*reworked IMPL::Web::Security
*refactoring
| author | sergey |
|---|---|
| date | Mon, 08 Oct 2012 03:37:37 +0400 |
| parents | 47f77e6409f7 |
| children | 8d36073411b1 |
comparison
equal
deleted
inserted
replaced
| 229:47f77e6409f7 | 230:6d8092d8ce1b |
|---|---|
| 1 package IMPL::Code::Loader; | 1 package IMPL::Code::Loader; |
| 2 use strict; | 2 use strict; |
| 3 use warnings; | 3 use warnings; |
| 4 | 4 |
| 5 use IMPL::lang qw(:declare :constants); | 5 use IMPL::Const qw(:prop); |
| 6 | 6 |
| 7 use IMPL::declare { | 7 use IMPL::declare { |
| 8 require => { | 8 require => { |
| 9 Exception => 'IMPL::Exception', | 9 Exception => 'IMPL::Exception', |
| 10 ArgumentException => '-IMPL::InvalidArgumentException' | 10 ArgumentException => '-IMPL::InvalidArgumentException' |
| 11 }, | 11 }, |
| 12 base => { | 12 base => { |
| 13 'IMPL::Object' => undef, | 13 'IMPL::Object' => undef, |
| 14 'IMPL::Object::Autofill' => '@_' | 14 'IMPL::Object::Autofill' => '@_' |
| 15 } | 15 }, |
| 16 props => [ | |
| 17 verifyNames => PROP_RO, | |
| 18 prefix => PROP_RO, | |
| 19 _pending => PROP_RW | |
| 20 ] | |
| 16 }; | 21 }; |
| 17 | 22 |
| 18 my $default; | 23 my $default; |
| 19 sub default { | 24 sub default { |
| 20 $default ||= new IMPL::Code::Loader; | 25 $default ||= new IMPL::Code::Loader; |
| 23 my $safe; | 28 my $safe; |
| 24 sub safe { | 29 sub safe { |
| 25 $safe ||= new IMPL::Code::Loader(verifyNames => 1); | 30 $safe ||= new IMPL::Code::Loader(verifyNames => 1); |
| 26 } | 31 } |
| 27 | 32 |
| 28 BEGIN { | 33 sub CTOR { |
| 29 public property verifyNames => PROP_GET | PROP_OWNERSET; | 34 my ($this) = @_; |
| 30 public property prefix => PROP_GET | PROP_OWNERSET; | 35 |
| 36 $this->_pending({}); | |
| 31 } | 37 } |
| 32 | |
| 33 | 38 |
| 34 sub Require { | 39 sub Require { |
| 35 my ($this,$package) = @_; | 40 my ($this,$package) = @_; |
| 36 | 41 |
| 37 if ($this->verifyNames) { | 42 if ($this->verifyNames) { |
| 42 $package = $this->prefix . '::' . $package if $this->prefix; | 47 $package = $this->prefix . '::' . $package if $this->prefix; |
| 43 | 48 |
| 44 my $file = join('/', split(/::/,$package)) . ".pm"; | 49 my $file = join('/', split(/::/,$package)) . ".pm"; |
| 45 | 50 |
| 46 require $file; | 51 require $file; |
| 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; | |
| 47 } | 65 } |
| 48 | 66 |
| 49 1; | 67 1; |
| 50 | 68 |
