1
|
1 package IMPL::Object::Abstract;
|
|
2 use strict;
|
|
3 use warnings;
|
|
4
|
|
5 use base qw(IMPL::Class::Meta);
|
|
6
|
|
7 our $MemoryLeakProtection;
|
|
8 my $Cleanup = 0;
|
|
9
|
|
10 my %cacheCTOR;
|
|
11
|
|
12 my $t = 0;
|
|
13 sub cache_ctor {
|
|
14 my $class = shift;
|
|
15
|
|
16 no strict 'refs';
|
|
17 my @sequence;
|
|
18
|
|
19 my $refCTORS = *{"${class}::CTOR"}{HASH};
|
|
20
|
|
21 foreach my $super ( @{"${class}::ISA"} ) {
|
|
22 my $superSequence = $cacheCTOR{$super} || cache_ctor($super);
|
|
23
|
|
24 my $mapper = $refCTORS ? $refCTORS->{$super} : undef;
|
|
25 if (ref $mapper eq 'CODE') {
|
|
26 if ($mapper == *_pass_throgh_mapper{CODE}) {
|
|
27 push @sequence,@$superSequence;
|
|
28 } else {
|
|
29 push @sequence, sub {
|
|
30 my $this = shift;
|
|
31 $this->$_($mapper->(@_)) foreach @$superSequence;
|
|
32 };
|
|
33 }
|
|
34 } else {
|
|
35 warn "Unsupported mapper type, in '$class' for the super class '$super'" if $mapper;
|
|
36 push @sequence, sub {
|
|
37 my $this = shift;
|
|
38 $this->$_() foreach @$superSequence;
|
|
39 };
|
|
40 }
|
|
41 }
|
|
42
|
|
43 push @sequence, *{"${class}::CTOR"}{CODE} if *{"${class}::CTOR"}{CODE};
|
|
44
|
|
45 $cacheCTOR{$class} = \@sequence;
|
|
46 return \@sequence;
|
|
47 }
|
|
48
|
|
49 sub callCTOR {
|
|
50 my $self = shift;
|
|
51 my $class = ref $self;
|
|
52
|
|
53 $self->$_(@_) foreach @{$cacheCTOR{$class} || cache_ctor($class)};
|
|
54 }
|
|
55
|
|
56 sub superCTOR {
|
|
57 my $this = shift;
|
|
58
|
|
59 warn "The mehod is deprecated, at " . caller;
|
|
60 }
|
|
61
|
|
62 sub toString {
|
|
63 my $self = shift;
|
|
64
|
|
65 return (ref $self || $self);
|
|
66 }
|
|
67
|
|
68 sub DESTROY {
|
|
69 if ($MemoryLeakProtection and $Cleanup) {
|
|
70 my $this = shift;
|
|
71 warn sprintf("Object leaks: %s of type %s %s",$this->can('ToString') ? $this->ToString : $this,ref $this,UNIVERSAL::can($this,'_dump') ? $this->_dump : '');
|
|
72 }
|
|
73 }
|
|
74
|
|
75 sub END {
|
|
76 $Cleanup = 1;
|
|
77 }
|
|
78
|
|
79 sub _pass_throgh_mapper {
|
|
80 @_;
|
|
81 }
|
|
82
|
|
83 sub PassThroughArgs {
|
|
84 my $class = shift;
|
|
85 $class = ref $class || $class;
|
|
86 no strict 'refs';
|
|
87 no warnings 'once';
|
|
88 ${"${class}::CTOR"}{$_} = \&_pass_throgh_mapper foreach @{"${class}::ISA"};
|
|
89 }
|
|
90
|
|
91 package self;
|
|
92
|
|
93 our $AUTOLOAD;
|
|
94 sub AUTOLOAD {
|
|
95 goto &{caller(). substr $AUTOLOAD,4};
|
|
96 }
|
|
97
|
|
98 package supercall;
|
|
99
|
|
100 our $AUTOLOAD;
|
|
101 sub AUTOLOAD {
|
|
102 my $sub;
|
|
103 my $methodName = substr $AUTOLOAD,11;
|
|
104 no strict 'refs';
|
|
105 $sub = $_->can($methodName) and $sub->(@_) foreach @{caller().'::ISA'};
|
|
106 }
|
|
107
|
|
108 =pod
|
|
109 =h1 SYNOPSIS
|
|
110
|
|
111 package MyBaseObject;
|
|
112 use base qw(IMPL::Object::Abstract);
|
|
113
|
|
114 sub new {
|
|
115 # own implementation of the new opeator
|
|
116 }
|
|
117
|
|
118 sub surrogate {
|
|
119 # own implementation of the surrogate operator
|
|
120 }
|
|
121
|
|
122 =h1 DESCRIPTION
|
|
123
|
|
124 Ðåàëèçàöèÿ ìåõàíèçìà âûçîâà êîíñòðóêòîðîâ è äðóãèõ âñïîìîãàòåëüíûõ âåùåé, êðîìå îïåðàòîðîâ
|
|
125 ñîçäàíèÿ ýêçåìïëÿðîâ.
|
2
|
126 =cut
|
1
|
127
|
|
128 1;
|