annotate Lib/IMPL/Class/Meta.pm @ 94:79bf75223afe

Fixed security related bugs
author wizard
date Thu, 29 Apr 2010 01:31:27 +0400
parents dc1da0389db7
children 6c25ea91c985
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
90
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
4 use Class::Data::Inheritable;
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
5 use Storable qw(dclone);
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
6
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
7 my %class_meta;
90
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
8 my %class_data;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
9
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
10 sub set_meta {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
11 my ($class,$meta_data) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
12 $class = ref $class if ref $class;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
13
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
14 # тут нельзя использовать стандартное исключение, поскольку для него используется
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
15 # класс IMPL::Object::Accessor, который наследуется от текущего класса
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
16 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
17
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
18 push @{$class_meta{$class}{ref $meta_data}},$meta_data;
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
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
21 sub get_meta {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
22 my ($class,$meta_class,$predicate,$deep) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
23 $class = ref $class if ref $class;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
24 no strict 'refs';
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
25 my @result;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
26
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
27 if ($deep) {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
28 @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
29 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
30
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
31 if ($predicate) {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
32 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
33 } else {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
34 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
35 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
36 wantarray ? @result : \@result;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
37 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
38
90
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
39 sub class_data {
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
40 my $class = shift;
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
41 $class = ref $class || $class;
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
42
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
43 if (@_ > 1) {
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
44 my ($name,$value) = @_;
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
45 return $class_data{$class}{$name} = $value;
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
46 } else {
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
47 my ($name) = @_;
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
48
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
49 if( exists $class_data{$class}{$name} ) {
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
50 $class_data{$class}{$name};
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
51 } else {
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
52 if ( my $value = $class->_find_class_data($name) ) {
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
53 $class_data{$class}{$name} = dclone($value);
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
54 } else {
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
55 undef;
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
56 }
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
57 }
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 }
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
60
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
61 sub _find_class_data {
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
62 my ($class,$name) = @_;
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
63
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
64 no strict 'refs';
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
65
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
66 exists $class_data{$_}{$name} and return $class_data{$_}{$name} foreach @{"${class}::ISA"};
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
67
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
68 my $val;
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
69 $val = $_->_find_class_data($name) and return $val foreach @{"${class}::ISA"};
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
70 }
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
71
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
72 1;
90
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
73
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
74 __END__
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
75
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
76 =pod
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
77
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
78 =head1 NAME
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
79
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
80 C<IMPL::Class::Meta> - информация хранимая на уровне класса.
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
81
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
82 =head1 SYNOPSIS
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
83
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
84 =begin code
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
85
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
86 package InfoMeta;
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
87
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
88 use base qw(IMPL::Object IMPL::Object::Autofill);
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
89 use IMPL::Class::Property;
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
90
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
91 __PACKAGE__->PassThroughArgs;
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
92
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
93 BEGIN {
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
94 public property name => prop_get | owner_set;
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
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
97 package InfoExMeta;
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
98 use base qw(InfoMeta);
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 __PACKAGE__->PassThroughArgs;
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
101
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
102 BEGIN {
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
103 public property description => prop_all;
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
104 }
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 package Foo;
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__->set_meta(new InfoMeta(name => 'info'));
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
109 __PACKAGE__->set_meta(new InfoExMeta(name => 'infoEx', description => 'extended info' ));
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
110
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
111 package main;
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 # 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
114 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
115
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
116 # get all InfoExMeta meta
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
117 @info = Foo->get_meta('InfoExMeta'); # will get only 'infoEx'
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 # get filtered meta
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
120 @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
121
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
122 =end code
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 =head1 DESCRIPTION
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
125
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
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
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
131 =head1 MEMBERS
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 =over
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 =item C<set_meta($meta_data)>
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
136
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
137 Добавляет метаданные C<$meta_data> к классу.
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
138
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
139 =item C<get_meta($meta_class,$predicate,$deep)>
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 Выбирает метаданные типа C<$meta_class> и его наследников, с возможностью фильтрации и получения
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
142 метаданных базовых классов.
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 =over
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 =item C<$meta_class>
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
147
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
148 Тип метаданных
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
149
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
150 =item C<$predicate>
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
151
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 ее выполнения метаданные будут включены в результат или нет. Получеат в качестве параметра
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
154 объект с метаданными, возвращает C<true> - включить метаданные в результа, C<false> - пропустить
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
155 метаданные как не подходящие. Также переменная C<$_> ссылается на текущий объект с метаданными.
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 =begin code
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
158
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
159 my @info = Foo->get_meta(
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
160 'InfoMeta',
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
161 sub { ref $_ eq 'InfoMeta'}, # exclude subclasses ('InfoExMeta')
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
162 1 # deep search
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
163 );
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
164
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
165 my @info = Foo->get_meta(
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
166 'InfoMeta',
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
167 sub {
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
168 my $item = shift;
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
169 ref $item eq 'InfoMeta' # exclude subclasses ('InfoExMeta')
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
170 },
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
171 1 # deep search
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
172 );
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
173
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
174 =end code
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
175
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
176 =item C<$deep>
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
177
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
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
180 =back
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
181
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
182 =item C<class_data($name,$new_value)>
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
183
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
184 В отличии от метаданных, C<class_data> не накапливает информацию,
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
185 а хранит только один экземпляр для одного ключа C<$name>.
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 Если новое значение не задано, то осуществляется выборка сохраненного,
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
188 если текущий класс не имеет сохраненного значения, то оно ищется в базовых
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
189 классах, затем копия найденного значения сохраняется в текущем классе и
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
190 возвращается наружу. Это позволяет базовым классам задавать значение по-умолчанию,
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
191 которые могут быть изменены или заменены субклассами.
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
192
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
193 =begin code
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 package Foo;
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
196 use base qw(IMPL::Class::Meta);
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 __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
199
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
200 sub say_version {
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
201 my ($self) = @_;
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
202
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
203 print $self->class_data(info)->{version};
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
204 }
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
205
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
206 package Bar;
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
207 use base qw(Foo);
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
208
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
209 __PACKAGE__->class_data('info')->{ language } = 'English';
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
210
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
211 package main;
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
212
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
213 Foo->class_data('info')->{version} = 2;
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
214 Bar->say_version; # will print '1';
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
215 Foo->say_version; # will print '2';
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 =end code
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
218
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
219 =back
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
220
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 49
diff changeset
221 =cut