annotate lib/IMPL/Object.pm @ 407:c6e90e02dd17 ref20150831

renamed Lib->lib
author cin
date Fri, 04 Sep 2015 19:40:23 +0300
parents
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::Object;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
2 use strict;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
3
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
4 use parent qw(IMPL::Object::Abstract);
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
5 use IMPL::require {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
6 ClassPropertyImplementor => 'IMPL::Code::DirectPropertyImplementor'
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
7 };
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
8
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
9 sub surrogate {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
10 bless {}, ref $_[0] || $_[0];
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
11 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
12
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
13 sub new {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
14 my $class = shift;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
15 my $self = bless {}, ref($class) || $class;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
16 $self->callCTOR(@_);
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
17
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
18 $self;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
19 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
20
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
21 1;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
22
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
23 __END__
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
24
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
25 =pod
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
26
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
27 =head1 SINOPSYS
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
28
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
29 =begin code
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
30
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
31 package Foo;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
32 use parent qw(IMPL::Object);
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
33
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
34 sub CTOR {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
35 my ($this,$arg) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
36 print "Foo: $arg\n";
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
37 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
38
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
39 package Bar;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
40 use parent qw(IMPL::Object);
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
41
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
42 sub CTOR {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
43 my ($this,$arg) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
44 print "Bar: $arg\n";
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
45 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
46
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
47 package Baz;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
48 use parent qw(Foo Bar);
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
49
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
50 our %CTOR = (
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
51 Foo => sub { my %args = @_; $args{Mazzi}; },
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
52 Bar => sub { my %args = @_; $args{Fugi}; }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
53 );
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
54
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
55 package Composite;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
56 use parent qw(Baz Foo Bar);
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
57
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
58 our %CTOR = (
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
59 Foo => undef,
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
60 Bar => undef
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
61 );
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
62
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
63 sub CTOR {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
64 my ($this,%args) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
65
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
66 print "Composite: $args{Text}\n";
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
67 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
68
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
69 package main;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
70
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
71 my $obj = new Composite(
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
72 Text => 'Hello World!',
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
73 Mazzi => 'Mazzi',
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
74 Fugi => 'Fugi'
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
75 );
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
76
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
77 # will print
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
78 #
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
79 # Foo: Mazzi
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
80 # Bar: Fugi
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
81 # Bar:
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
82 # Composite: Hello World!
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
83
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
84 =end code
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
85
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
86 =head1 Description
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
87
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
88 Базовый класс для объектов, основанных на хеше.
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
89
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
90 =head1 Members
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
91
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
92 =over
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
93
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
94 =item operator C<new>(@args)
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
95
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
96 Создает экземпляр объекта и вызывает конструктор с параметрами @args.
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
97
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
98 =item operator C<surrogate>()
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
99
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
100 Создает неинициализированный экземпляр объекта.
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
101
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
102 =back
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
103
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
104 =head1 Cavearts
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
105
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
106 Нужно заметить, что директива C<use parent> работает не совсем прозрачно, если в нашем примере
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
107 класс C<Composite> наследуется от C<Baz>, а затем C<Foo>, то наследование от
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
108 C<Foo> не произойдет поскольку он уже имеется в C<Baz>. Вот не задача:)
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
109
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
110 =cut