Mercurial > pub > Impl
annotate Lib/IMPL/Object.pm @ 276:8a5da17d7ef9
*IMPL::Class refactoring property definition mechanism (incomplete).
author | sergey |
---|---|
date | Thu, 31 Jan 2013 17:37:44 +0400 |
parents | 6d8092d8ce1b |
children | 4ddb27ff4a0b |
rev | line source |
---|---|
49 | 1 package IMPL::Object; |
2 use strict; | |
3 | |
165 | 4 use parent qw(IMPL::Object::Abstract); |
230 | 5 require IMPL::Class::Property::Direct; |
276
8a5da17d7ef9
*IMPL::Class refactoring property definition mechanism (incomplete).
sergey
parents:
230
diff
changeset
|
6 use IMPL::Const qw(:prop); |
49 | 7 |
8 sub surrogate { | |
9 bless {}, ref $_[0] || $_[0]; | |
10 } | |
11 | |
12 sub new { | |
13 my $class = shift; | |
14 my $self = bless {}, ref($class) || $class; | |
15 $self->callCTOR(@_); | |
16 | |
17 $self; | |
18 } | |
19 | |
20 sub _PropertyImplementor { | |
21 'IMPL::Class::Property::Direct' | |
22 } | |
23 | |
276
8a5da17d7ef9
*IMPL::Class refactoring property definition mechanism (incomplete).
sergey
parents:
230
diff
changeset
|
24 sub ImplementProperty { |
8a5da17d7ef9
*IMPL::Class refactoring property definition mechanism (incomplete).
sergey
parents:
230
diff
changeset
|
25 my ($self,$name,$attributes) = @_; |
8a5da17d7ef9
*IMPL::Class refactoring property definition mechanism (incomplete).
sergey
parents:
230
diff
changeset
|
26 |
8a5da17d7ef9
*IMPL::Class refactoring property definition mechanism (incomplete).
sergey
parents:
230
diff
changeset
|
27 $attributes = { |
8a5da17d7ef9
*IMPL::Class refactoring property definition mechanism (incomplete).
sergey
parents:
230
diff
changeset
|
28 get => $attributes & PROP_GET, |
8a5da17d7ef9
*IMPL::Class refactoring property definition mechanism (incomplete).
sergey
parents:
230
diff
changeset
|
29 set => $attributes & PROP_SET, |
8a5da17d7ef9
*IMPL::Class refactoring property definition mechanism (incomplete).
sergey
parents:
230
diff
changeset
|
30 isList => $attributes & PROP_LIST |
8a5da17d7ef9
*IMPL::Class refactoring property definition mechanism (incomplete).
sergey
parents:
230
diff
changeset
|
31 } unless ref $attributes; |
8a5da17d7ef9
*IMPL::Class refactoring property definition mechanism (incomplete).
sergey
parents:
230
diff
changeset
|
32 |
8a5da17d7ef9
*IMPL::Class refactoring property definition mechanism (incomplete).
sergey
parents:
230
diff
changeset
|
33 $self->_ProppertyImplementor->Implement($name,$attributes); |
8a5da17d7ef9
*IMPL::Class refactoring property definition mechanism (incomplete).
sergey
parents:
230
diff
changeset
|
34 } |
8a5da17d7ef9
*IMPL::Class refactoring property definition mechanism (incomplete).
sergey
parents:
230
diff
changeset
|
35 |
53 | 36 1; |
37 | |
38 __END__ | |
39 | |
49 | 40 =pod |
53 | 41 |
148
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
64
diff
changeset
|
42 =head1 SINOPSYS |
49 | 43 |
64 | 44 =begin code |
45 | |
49 | 46 package Foo; |
165 | 47 use parent qw(IMPL::Object); |
49 | 48 |
49 sub CTOR { | |
50 my ($this,$arg) = @_; | |
51 print "Foo: $arg\n"; | |
52 } | |
53 | |
54 package Bar; | |
165 | 55 use parent qw(IMPL::Object); |
49 | 56 |
57 sub CTOR { | |
58 my ($this,$arg) = @_; | |
59 print "Bar: $arg\n"; | |
60 } | |
61 | |
62 package Baz; | |
165 | 63 use parent qw(Foo Bar); |
49 | 64 |
65 our %CTOR = ( | |
66 Foo => sub { my %args = @_; $args{Mazzi}; }, | |
67 Bar => sub { my %args = @_; $args{Fugi}; } | |
68 ); | |
69 | |
70 package Composite; | |
165 | 71 use parent qw(Baz Foo Bar); |
49 | 72 |
73 our %CTOR = ( | |
74 Foo => undef, | |
75 Bar => undef | |
76 ); | |
77 | |
78 sub CTOR { | |
79 my ($this,%args) = @_; | |
80 | |
81 print "Composite: $args{Text}\n"; | |
82 } | |
83 | |
84 package main; | |
85 | |
86 my $obj = new Composite( | |
87 Text => 'Hello World!', | |
88 Mazzi => 'Mazzi', | |
89 Fugi => 'Fugi' | |
90 ); | |
91 | |
92 # will print | |
93 # | |
94 # Foo: Mazzi | |
95 # Bar: Fugi | |
96 # Bar: | |
97 # Composite: Hello World! | |
98 | |
64 | 99 =end code |
100 | |
53 | 101 =head1 Description |
102 | |
180 | 103 Базовый класс для объектов, основанных на хеше. |
49 | 104 |
53 | 105 =head1 Members |
49 | 106 |
53 | 107 =over |
49 | 108 |
109 =item operator C<new>(@args) | |
110 | |
180 | 111 Создает экземпляр объекта и вызывает конструктор с параметрами @args. |
49 | 112 |
113 =item operator C<surrogate>() | |
114 | |
180 | 115 Создает неинициализированный экземпляр объекта. |
49 | 116 |
117 =back | |
118 | |
53 | 119 =head1 Cavearts |
49 | 120 |
180 | 121 Нужно заметить, что директива C<use parent> работает не совсем прозрачно, если в нашем примере |
122 класс C<Composite> наследуется от C<Baz>, а затем C<Foo>, то наследование от | |
123 C<Foo> не произойдет поскольку он уже имеется в C<Baz>. Вот не задача:) | |
49 | 124 |
125 =cut |