49
|
1 package IMPL::Config::Class;
|
|
2 use strict;
|
|
3 use warnings;
|
|
4
|
165
|
5 use parent qw(IMPL::Config);
|
49
|
6 use IMPL::Exception;
|
|
7 use IMPL::Class::Property;
|
196
|
8 use Carp qw(carp);
|
49
|
9
|
|
10 BEGIN {
|
196
|
11 carp "the module is deprecated";
|
|
12
|
49
|
13 public property Type => prop_all;
|
|
14 public property Parameters => prop_all;
|
|
15 public property IsSingleton => prop_all;
|
|
16 private property _Instance => prop_all;
|
|
17 }
|
|
18
|
|
19 __PACKAGE__->PassThroughArgs;
|
|
20
|
|
21 sub CTOR {
|
|
22 my $this = shift;
|
|
23
|
|
24 die new IMPL::Exception("A Type parameter is required") unless $this->Type;
|
|
25
|
92
|
26 warn "IMPL::Config::Class is absolute, use IMPL::Config::Activator instead";
|
49
|
27 }
|
|
28
|
|
29 sub _is_class {
|
|
30 no strict 'refs';
|
|
31 scalar keys %{"$_[0]::"} ? 1 : 0;
|
|
32 }
|
|
33
|
|
34 sub instance {
|
|
35 my $this = shift;
|
|
36
|
|
37 my $type = $this->Type;
|
|
38
|
|
39 if ($this->IsSingleton) {
|
|
40 if ($this->_Instance) {
|
|
41 return $this->_Instance;
|
|
42 } else {
|
|
43 my %args = (%{$this->Parameters || {}},@_);
|
|
44 eval "require $type" unless _is_class($type);
|
|
45 my $inst = $type->new(%args);
|
|
46 $this->_Instance($inst);
|
|
47 return $inst;
|
|
48 }
|
|
49 } else {
|
|
50 my %args = (%{$this->Parameters || {}},@_);
|
|
51 eval "require $type" unless _is_class($type);
|
|
52 return $type->new(%args);
|
|
53 }
|
|
54 }
|
|
55
|
|
56 1;
|