0
|
1 package IMPL::Object;
|
|
2 use strict;
|
|
3
|
2
|
4 use base qw(IMPL::Object::Abstract);
|
0
|
5
|
|
6 sub surrogate {
|
|
7 bless {}, ref $_[0] || $_[0];
|
|
8 }
|
|
9
|
2
|
10 sub new {
|
0
|
11 my $class = shift;
|
2
|
12 my $self = bless {}, ref($class) || $class;
|
|
13 $self->callCTOR(@_);
|
|
14
|
|
15 $self;
|
0
|
16 }
|
|
17
|
|
18 =pod
|
|
19 =h1 SYNOPSIS
|
|
20
|
|
21 package Foo;
|
|
22 use base qw(IMPL::Object);
|
|
23
|
|
24 sub CTOR {
|
|
25 my ($this,$arg) = @_;
|
|
26 print "Foo: $arg\n";
|
|
27 }
|
|
28
|
|
29 package Bar;
|
|
30 use base qw(IMPL::Object);
|
|
31
|
|
32 sub CTOR {
|
|
33 my ($this,$arg) = @_;
|
|
34 print "Bar: $arg\n";
|
|
35 }
|
|
36
|
|
37 package Baz;
|
|
38 use base qw(Foo Bar);
|
|
39
|
|
40 our %CTOR = (
|
|
41 Foo => sub { my %args = @_; $args{Mazzi}; },
|
|
42 Bar => sub { my %args = @_; $args{Fugi}; }
|
|
43 );
|
|
44
|
|
45 package Composite;
|
|
46 use base qw(Baz Foo Bar);
|
|
47
|
|
48 our %CTOR = (
|
|
49 Foo => undef,
|
|
50 Bar => undef
|
|
51 );
|
|
52
|
|
53 sub CTOR {
|
|
54 my ($this,%args) = @_;
|
|
55
|
|
56 print "Composite: $args{Text}\n";
|
|
57 }
|
|
58
|
|
59 package main;
|
|
60
|
|
61 my $obj = new Composite(
|
|
62 Text => 'Hello World!',
|
|
63 Mazzi => 'Mazzi',
|
|
64 Fugi => 'Fugi'
|
|
65 );
|
|
66
|
|
67 # will print
|
|
68 #
|
|
69 # Foo: Mazzi
|
|
70 # Bar: Fugi
|
|
71 # Bar:
|
|
72 # Composite: Hello World!
|
|
73
|
|
74 =h1 Description
|
2
|
75 Áàçîâûé êëàññ äëÿ îáúåêòîâ, îñíîâàííûõ íà õåøå.
|
0
|
76
|
|
77 =h1 Members
|
2
|
78
|
|
79 =level 4
|
|
80
|
|
81 =item operator C<new>(@args)
|
|
82
|
|
83 Ñîçäàåò ýêçåìïëÿð îáúåêòà è âûçûâàåò êîíñòðóêòîð ñ ïàðàìåòðàìè @args.
|
|
84
|
|
85 =item operator C<surrogate>()
|
|
86
|
|
87 Ñîçäàåò íåèíèöèàëèçèðîâàííûé ýêçåìïëÿð îáúåêòà.
|
|
88
|
|
89 =back
|
|
90
|
|
91 =ð1 Cavearts
|
|
92
|
|
93 Íóæíî çàìåòèòü, ÷òî äèðåêòèâà C<use base> ðàáîòàåò íå ñîâñåì ïðîçðà÷íî, åñëè â íàøåì ïðèìåðå
|
|
94 êëàññ C<Composite> íàñëåäóåòñÿ îò C<Baz>, à çàòåì C<Foo>, òî íàñëåäîâàíèå îò
|
|
95 C<Foo> íå ïðîèçîéäåò ïîñêîëüêó îí óæå èìååòñÿ â C<Baz>. Âîò íå çàäà÷à:)
|
|
96
|
0
|
97 =cut
|
|
98
|
|
99 1; |