Mercurial > pub > Impl
annotate Lib/IMPL/Code/Loader.pm @ 229:47f77e6409f7
heavily reworked the resource model of the web application:
*some ResourcesContraact functionality moved to Resource
+Added CustomResource
*Corrected action handlers
author | sergey |
---|---|
date | Sat, 29 Sep 2012 02:34:47 +0400 |
parents | a8db61d0ed33 |
children | 6d8092d8ce1b |
rev | line source |
---|---|
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) { |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
209
diff
changeset
|
38 $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
|
39 or die ArgumentException->new(package => 'Invalid package name') ; |
209 | 40 } |
194 | 41 |
229
47f77e6409f7
heavily reworked the resource model of the web application:
sergey
parents:
209
diff
changeset
|
42 $package = $this->prefix . '::' . $package if $this->prefix; |
194 | 43 |
209 | 44 my $file = join('/', split(/::/,$package)) . ".pm"; |
194 | 45 |
209 | 46 require $file; |
165 | 47 } |
48 | |
49 1; | |
50 |