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
|
24
|
83 sub PassArgs {
|
|
84 \&_pass_throgh_mapper;
|
|
85 }
|
|
86
|
1
|
87 sub PassThroughArgs {
|
|
88 my $class = shift;
|
|
89 $class = ref $class || $class;
|
|
90 no strict 'refs';
|
|
91 no warnings 'once';
|
|
92 ${"${class}::CTOR"}{$_} = \&_pass_throgh_mapper foreach @{"${class}::ISA"};
|
|
93 }
|
|
94
|
|
95 package self;
|
|
96
|
|
97 our $AUTOLOAD;
|
|
98 sub AUTOLOAD {
|
|
99 goto &{caller(). substr $AUTOLOAD,4};
|
|
100 }
|
|
101
|
|
102 package supercall;
|
|
103
|
|
104 our $AUTOLOAD;
|
|
105 sub AUTOLOAD {
|
|
106 my $sub;
|
|
107 my $methodName = substr $AUTOLOAD,11;
|
|
108 no strict 'refs';
|
|
109 $sub = $_->can($methodName) and $sub->(@_) foreach @{caller().'::ISA'};
|
|
110 }
|
|
111
|
|
112 =pod
|
|
113 =h1 SYNOPSIS
|
|
114
|
|
115 package MyBaseObject;
|
|
116 use base qw(IMPL::Object::Abstract);
|
|
117
|
|
118 sub new {
|
|
119 # own implementation of the new opeator
|
|
120 }
|
|
121
|
|
122 sub surrogate {
|
|
123 # own implementation of the surrogate operator
|
|
124 }
|
|
125
|
|
126 =h1 DESCRIPTION
|
|
127
|
|
128 ,
|
|
129 .
|
2
|
130 =cut
|
1
|
131
|
|
132 1;
|