165
|
1 package IMPL::Code::Loader;
|
|
2 use strict;
|
|
3 use warnings;
|
|
4
|
209
|
5 use IMPL::lang qw(:declare :constants);
|
|
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' => '@_'
|
|
15 }
|
|
16 };
|
165
|
17
|
209
|
18 my $default;
|
|
19 sub default {
|
|
20 $default ||= new IMPL::Code::Loader;
|
165
|
21 }
|
|
22
|
209
|
23 my $safe;
|
|
24 sub safe {
|
|
25 $safe ||= new IMPL::Code::Loader(verifyNames => 1);
|
|
26 }
|
|
27
|
|
28 BEGIN {
|
|
29 public property verifyNames => PROP_GET | PROP_OWNERSET;
|
|
30 public property prefix => PROP_GET | PROP_OWNERSET;
|
|
31 }
|
|
32
|
|
33
|
165
|
34 sub Require {
|
209
|
35 my ($this,$package) = @_;
|
194
|
36
|
209
|
37 if ($this->verifyNames) {
|
|
38 $package =~ m/^([a-zA-Z_0-9]+(?:::[a-zA-Z_0-9]+)*)$/ or die ArgumentException->new("package") ;
|
|
39 }
|
194
|
40
|
209
|
41 $package = $this->prefix . $package if $this->prefix;
|
194
|
42
|
209
|
43 my $file = join('/', split(/::/,$package)) . ".pm";
|
194
|
44
|
209
|
45 require $file;
|
165
|
46 }
|
|
47
|
|
48 1;
|
|
49
|