annotate lib/IMPL/Class/Template.pm @ 421:7798345304bc ref20150831

working on IMPL::Config, removed old stuff
author cin
date Sun, 16 Jul 2017 22:59:39 +0300
parents ee36115f6a34
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
407
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
1 package IMPL::Class::Template;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
2 use strict;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
3 use IMPL::lang;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
4
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
5 sub makeName {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
6 my ($class,@params) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
7
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
8 $_ =~ s/^.*::(\w+)$/$1/ foreach @params;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
9 return join('',$class,@params);
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
10 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
11
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
12 1;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
13
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
14 __END__
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
15
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
16 =pod
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
17
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
18 =head1 NAME
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
19
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
20 C<IMPL::Class::Template> базовый класс для шаблонов.
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
21
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
22 =head1 SYNPOSIS
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
23
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
24 =begin code
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
25
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
26 package KeyValuePair;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
27
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
28 use IMPL::Class::Property;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
29
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
30 use IMPL::template (
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
31 parameters => [qw(TKey TValue))],
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
32 base => [qw(IMPL::Object IMPL::Object::Autofill)],
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
33 declare => sub {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
34 my ($class) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
35 public $class->CreateProperty(key => prop_get | owner_set, { type => $class->TKey } );
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
36 public $class->CreateProperty(value => prop_all, { type => $class->TValue} );
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
37
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
38 $class->PassThroughArgs;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
39 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
40 );
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
41
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
42 BEGIN {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
43 public property id => prop_get | owner_set, { type => 'integer'};
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
44 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
45
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
46 __PACKAGE__->PassThroughArgs;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
47
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
48 package MyCollection;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
49
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
50 use IMPL::Class::Property;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
51
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
52 use IMPL::lang;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
53 use IMPL::template(
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
54 parameters => [qw(TKey TValue)],
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
55 base => [qw(IMPL::Object)],
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
56 declare => sub {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
57 my ($class) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
58 my $item_t = spec KeyValuePair($class->TKey,$class->TValue);
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
59
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
60 public $class->CreateProperty(items => prop_get | prop_list, { type => $item_t } )
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
61
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
62 $class->static_accessor( ItemType => $item_t );
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
63 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
64 )
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
65
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
66 sub Add {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
67 my ($this,$key,$value) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
68
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
69 die new IMPL::ArgumentException( key => "Invalid argument type" ) unless is $key, $this->TKey;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
70 die new IMPL::ArgumentException( value => "Invalid argument type" ) unless is $value, $this->TValue;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
71
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
72 $this->items->AddLast( $this->ItemType->new( key => $key, value => $value ) );
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
73 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
74
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
75 =end code
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
76
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
77 =head1 DESCRIPTION
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
78
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
79 Шаблоны используются для динамической генерации классов. Процесс создания класса
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
80 по шаблону называется специализацией, при этом создается новый класс:
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
81
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
82 =over
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
83
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
84 =item 1
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
85
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
86 Обявляется новый пакет с именем, вычисленным из имени и параметров шаблона
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
87
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
88 =item 2
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
89
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
90 Формируется массив C<@ISA> для созаднного класса, в который добавляется имя шаблона
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
91
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
92 =item 3
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
93
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
94 Формируются методы с именами параметров шаблона, возвращающие реальные значения параметров
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
95
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
96 =item 4
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
97
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
98 Вызывается метод для конструирования специализиции
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
99
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
100 =back
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
101
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
102 =head1 MEMBERS
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
103
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
104 =over
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
105
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
106 =item C<spec(@params)>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
107
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
108 Метод, создающий специализацию шаблона. Может быть вызван как оператор.
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
109
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
110 =back
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
111
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
112 =cut