annotate Lib/IMPL/Class/Meta.pm @ 197:6b1dda998839

Added IMPL::declare, IMPL::require, to simplify module definitions IMPL::Transform now admires object inheritance while searching for the transformation Added HTTP some exceptions IMPL::Web::Application::RestResource almost implemented
author sergey
date Thu, 19 Apr 2012 02:10:02 +0400
parents 4d0e1962161c
children a8db61d0ed33
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
1 package IMPL::Class::Meta;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
2 use strict;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
3
173
aaab45153411 minor bugfixes
sourcer
parents: 171
diff changeset
4 use IMPL::clone qw(clone);
90
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
5
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
6 my %class_meta;
90
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
7 my %class_data;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
8
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
9 sub set_meta {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
10 my ($class,$meta_data) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
11 $class = ref $class if ref $class;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
12
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 173
diff changeset
13 # тут нельзя использовать стандартное исключение, поскольку для него используется
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 173
diff changeset
14 # класс IMPL::Object::Accessor, который наследуется от текущего класса
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
15 die "The meta_data parameter should be an object" if not ref $meta_data;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
16
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
17 push @{$class_meta{$class}{ref $meta_data}},$meta_data;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
18 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
19
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
20 sub get_meta {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
21 my ($class,$meta_class,$predicate,$deep) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
22 $class = ref $class if ref $class;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
23 no strict 'refs';
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
24 my @result;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
25
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
26 if ($deep) {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
27 @result = map { $_->can('get_meta') ? $_->get_meta($meta_class,$predicate,$deep) : () } @{$class.'::ISA'};
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
28 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
29
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
30 if ($predicate) {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
31 push @result,grep( &$predicate($_), map( @{$class_meta{$class}{$_}}, grep( $_->isa($meta_class), keys %{$class_meta{$class} || {}} ) ) );
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
32 } else {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
33 push @result, map( @{$class_meta{$class}{$_} || []}, grep( $_->isa($meta_class), keys %{$class_meta{$class} || {}} ) );
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
34 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
35 wantarray ? @result : \@result;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
36 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
37
90
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
38 sub class_data {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
39 my $class = shift;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
40 $class = ref $class || $class;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
41
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
42 if (@_ > 1) {
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
43 my ($name,$value) = @_;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
44 return $class_data{$class}{$name} = $value;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
45 } else {
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
46 my ($name) = @_;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
47
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
48 if( exists $class_data{$class}{$name} ) {
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
49 $class_data{$class}{$name};
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
50 } else {
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
51 if ( my $value = $class->_find_class_data($name) ) {
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
52 $class_data{$class}{$name} = clone($value);
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
53 } else {
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
54 undef;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
55 }
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
56 }
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
57 }
90
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
58 }
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
59
163
6ce1f052b90a temp commit
wizard
parents: 153
diff changeset
60 sub static_accessor {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
61 my ($class,$name,$value) = @_;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
62 $class = ref $class || $class;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
63
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
64 no strict 'refs';
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
65
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
66 *{"${class}::${name}"} = sub {
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
67 if (@_ > 1) {
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
68 my $self = shift;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
69 $self = ref $self || $self;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
70
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
71 if ($class ne $self) {
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
72 $self->static_accessor( $name => $_[0]); # define own class data
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
73 } else {
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
74 $value = $_[0];
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
75 }
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
76 } else {
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
77 $value;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
78 }
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
79 };
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
80 $value
163
6ce1f052b90a temp commit
wizard
parents: 153
diff changeset
81 };
6ce1f052b90a temp commit
wizard
parents: 153
diff changeset
82
90
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
83 sub _find_class_data {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
84 my ($class,$name) = @_;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
85
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
86 no strict 'refs';
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
87
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
88 exists $class_data{$_}{$name} and return $class_data{$_}{$name} foreach @{"${class}::ISA"};
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
89
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
90 my $val;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
91 $val = $_->can('_find_class_data') ? $_->_find_class_data($name) : undef and return $val foreach @{"${class}::ISA"};
90
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
92 }
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
93
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
94 1;
90
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
95
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
96 __END__
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
97
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
98 =pod
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
99
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
100 =head1 NAME
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
101
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 173
diff changeset
102 C<IMPL::Class::Meta> - информация хранимая на уровне класса.
90
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
103
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
104 =head1 SYNOPSIS
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
105
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
106 =begin code
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
107
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
108 package InfoMeta;
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
109
165
76515373dac0 Added Class::Template,
wizard
parents: 164
diff changeset
110 use parent qw(IMPL::Object IMPL::Object::Autofill);
90
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
111 use IMPL::Class::Property;
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
112
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
113 __PACKAGE__->PassThroughArgs;
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
114
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
115 BEGIN {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
116 public property name => prop_get | owner_set;
90
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
117 }
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
118
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
119 package InfoExMeta;
165
76515373dac0 Added Class::Template,
wizard
parents: 164
diff changeset
120 use parent qw(InfoMeta);
90
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
121
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
122 __PACKAGE__->PassThroughArgs;
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
123
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
124 BEGIN {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
125 public property description => prop_all;
90
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
126 }
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
127
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
128 package Foo;
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
129
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
130 __PACKAGE__->set_meta(new InfoMeta(name => 'info'));
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
131 __PACKAGE__->set_meta(new InfoExMeta(name => 'infoEx', description => 'extended info' ));
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
132
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
133 package main;
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
134
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
135 # get all InfoMeta, InfoExMeta will be included, becouse it's derived from InfoMeta
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
136 my @info = Foo->get_meta('InfoMeta'); # will get two objects, 'info' and 'infoEx';
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
137
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
138 # get all InfoExMeta meta
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
139 @info = Foo->get_meta('InfoExMeta'); # will get only 'infoEx'
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
140
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
141 # get filtered meta
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
142 @info = Foo->get_meta('InfoMeta', sub { $_->name eq 'info'} ); # will get only 'info'
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
143
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
144 =end code
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
145
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
146 =head1 DESCRIPTION
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
147
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 173
diff changeset
148 Позвоялет расширять информацию о типах (класса) при помощи метаданных, метаданными являются любые объекты,
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 173
diff changeset
149 притом выборка метаданных приоизводится по их типу (классу), что позволяет выбрать все однотипные метаданные.
90
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
150
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 173
diff changeset
151 Существует возможность выборки метаданных с учетом унаследованных от базовых классов
90
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
152
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
153 =head1 MEMBERS
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
154
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
155 =over
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
156
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
157 =item C<set_meta($meta_data)>
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
158
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 173
diff changeset
159 Добавляет метаданные C<$meta_data> к классу.
90
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
160
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
161 =item C<get_meta($meta_class,$predicate,$deep)>
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
162
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 173
diff changeset
163 Выбирает метаданные типа C<$meta_class> и его наследников, с возможностью фильтрации и получения
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 173
diff changeset
164 метаданных базовых классов.
90
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
165
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
166 =over
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
167
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
168 =item C<$meta_class>
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
169
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 173
diff changeset
170 Тип метаданных
90
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
171
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
172 =item C<$predicate>
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
173
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 173
diff changeset
174 Подпрограмма, которая будет вызываться для каждых найденных метаданных и на основе результата
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 173
diff changeset
175 ее выполнения метаданные будут включены в результат или нет. Получеат в качестве параметра
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 173
diff changeset
176 объект с метаданными, возвращает C<true> - включить метаданные в результа, C<false> - пропустить
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 173
diff changeset
177 метаданные как не подходящие. Также переменная C<$_> ссылается на текущий объект с метаданными.
90
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
178
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
179 =begin code
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
180
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
181 my @info = Foo->get_meta(
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
182 'InfoMeta',
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
183 sub { ref $_ eq 'InfoMeta'}, # exclude subclasses ('InfoExMeta')
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
184 1 # deep search
90
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
185 );
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
186
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
187 my @info = Foo->get_meta(
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
188 'InfoMeta',
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
189 sub {
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
190 my $item = shift;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
191 ref $item eq 'InfoMeta' # exclude subclasses ('InfoExMeta')
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
192 },
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
193 1 # deep search
90
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
194 );
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
195
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
196 =end code
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
197
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
198 =item C<$deep>
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
199
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 173
diff changeset
200 Осуществлять поиск по базовым классам.
90
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
201
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
202 =back
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
203
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
204 =item C<class_data($name,$new_value)>
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
205
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 173
diff changeset
206 В отличии от метаданных, C<class_data> не накапливает информацию,
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 173
diff changeset
207 а хранит только один экземпляр для одного ключа C<$name>.
90
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
208
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 173
diff changeset
209 Если новое значение не задано, то осуществляется выборка сохраненного,
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 173
diff changeset
210 если текущий класс не имеет сохраненного значения, то оно ищется в базовых
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 173
diff changeset
211 классах, затем копия найденного значения сохраняется в текущем классе и
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 173
diff changeset
212 возвращается наружу. Это позволяет базовым классам задавать значение по-умолчанию,
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 173
diff changeset
213 которые могут быть изменены или заменены субклассами.
90
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
214
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
215 =begin code
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
216
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
217 package Foo;
165
76515373dac0 Added Class::Template,
wizard
parents: 164
diff changeset
218 use parent qw(IMPL::Class::Meta);
90
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
219
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
220 __PACKAGE__->class_data( info => { version => 1 } ); # will be default for all subclasses
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
221
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
222 sub say_version {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
223 my ($self) = @_;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
224
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
225 print $self->class_data('info')->{version};
90
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
226 }
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
227
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
228 package Bar;
165
76515373dac0 Added Class::Template,
wizard
parents: 164
diff changeset
229 use parent qw(Foo);
90
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
230
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
231 __PACKAGE__->class_data('info')->{ language } = 'English';
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
232
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
233 package main;
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
234
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
235 Foo->class_data('info')->{version} = 2;
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
236 Bar->say_version; # will print '1';
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
237 Foo->say_version; # will print '2';
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
238
163
6ce1f052b90a temp commit
wizard
parents: 153
diff changeset
239 =end code
6ce1f052b90a temp commit
wizard
parents: 153
diff changeset
240
6ce1f052b90a temp commit
wizard
parents: 153
diff changeset
241 =item C<static_accessor($name[,$value])>
6ce1f052b90a temp commit
wizard
parents: 153
diff changeset
242
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 173
diff changeset
243 Создает статическое свойство с именем C<$name> и начальным значением C<$value>.
163
6ce1f052b90a temp commit
wizard
parents: 153
diff changeset
244
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 173
diff changeset
245 Использование данного свойство аналогично использованию C<class_data>, за исключением
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 173
diff changeset
246 того, что C<class_data> гарантирует, что наследник обладает собственной копией данных,
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 173
diff changeset
247 изменение которых не коснется ни базового класса, ни соседей.
163
6ce1f052b90a temp commit
wizard
parents: 153
diff changeset
248
6ce1f052b90a temp commit
wizard
parents: 153
diff changeset
249 =begin code
6ce1f052b90a temp commit
wizard
parents: 153
diff changeset
250
6ce1f052b90a temp commit
wizard
parents: 153
diff changeset
251 package Foo;
165
76515373dac0 Added Class::Template,
wizard
parents: 164
diff changeset
252 use parent qw(IMPL::Class::Meta);
163
6ce1f052b90a temp commit
wizard
parents: 153
diff changeset
253
6ce1f052b90a temp commit
wizard
parents: 153
diff changeset
254 __PACKAGE__->static_accessor( info => { version => 1 } );
6ce1f052b90a temp commit
wizard
parents: 153
diff changeset
255
6ce1f052b90a temp commit
wizard
parents: 153
diff changeset
256 package Bar;
165
76515373dac0 Added Class::Template,
wizard
parents: 164
diff changeset
257 use parent qw(Foo);
163
6ce1f052b90a temp commit
wizard
parents: 153
diff changeset
258
6ce1f052b90a temp commit
wizard
parents: 153
diff changeset
259 __PACKAGE__->info->{language} = 'English'; # Foo->info->{language} will become 'English' to!!!
6ce1f052b90a temp commit
wizard
parents: 153
diff changeset
260 __PACKAGE__->info({language => 'English'}); # will define own 'info' but will loose original data.
6ce1f052b90a temp commit
wizard
parents: 153
diff changeset
261
6ce1f052b90a temp commit
wizard
parents: 153
diff changeset
262 =end code
6ce1f052b90a temp commit
wizard
parents: 153
diff changeset
263
90
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
264
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
265 =back
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
266
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
267 =cut