annotate Lib/IMPL/Config/Class.pm @ 14:65a7bb156fb7

Дом модель и схема
author Sergey
date Fri, 04 Sep 2009 16:38:15 +0400
parents 03e58a454b20
children 16ada169ca75
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
1 package IMPL::Config::Class;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
2 use strict;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
3 use warnings;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
4
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
5 use base qw(IMPL::Config);
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
6 use IMPL::Exception;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
7 use IMPL::Class::Property;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
8
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
9 BEGIN {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
10 public property Type => prop_all;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
11 public property Parameters => prop_all;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
12 public property IsSingleton => prop_all;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
13 private property _Instance => prop_all;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
14 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
15
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
16 __PACKAGE__->PassThroughArgs;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
17
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
18 sub CTOR {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
19 my $this = shift;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
20
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
21 die new IMPL::Exception("A Type parameter is required") unless $this->Type;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
22
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
23 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
24
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
25 sub _is_class {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
26 no strict 'refs';
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
27 scalar keys %{"$_[0]::"} ? 1 : 0;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
28 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
29
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
30 sub instance {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
31 my $this = shift;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
32
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
33 my $type = $this->Type;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
34
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
35 if ($this->IsSingleton) {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
36 if ($this->_Instance) {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
37 return $this->_Instance;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
38 } else {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
39 my %args = (%{$this->Parameters || {}},@_);
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
40 eval "require $type" unless _is_class($type);
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
41 my $inst = $type->new(%args);
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
42 $this->_Instance($inst);
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
43 return $inst;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
44 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
45 } else {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
46 my %args = (%{$this->Parameters || {}},@_);
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
47 eval "require $type" unless _is_class($type);
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
48 return $type->new(%args);
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
49 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
50 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
51
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
52 1;