annotate Lib/IMPL/Class/Template.pm @ 337:f4e14f32cf54

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