Mercurial > pub > Impl
annotate Lib/IMPL/Object/Abstract.pm @ 158:a9f4ba4783eb
Minor changes
author | wizard |
---|---|
date | Tue, 02 Nov 2010 20:17:22 +0300 |
parents | b56ebc31bf18 |
children | eb3e9861a761 |
rev | line source |
---|---|
49 | 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"} ) { | |
90 | 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; | |
144
b56ebc31bf18
Empty nodes no more created while transforming a post request to the DOM document
wizard
parents:
122
diff
changeset
|
32 } if @$superSequence; |
90 | 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; | |
144
b56ebc31bf18
Empty nodes no more created while transforming a post request to the DOM document
wizard
parents:
122
diff
changeset
|
39 } if @$superSequence; |
90 | 40 } |
49 | 41 } |
42 | |
43 push @sequence, *{"${class}::CTOR"}{CODE} if *{"${class}::CTOR"}{CODE}; | |
44 | |
45 $cacheCTOR{$class} = \@sequence; | |
46 return \@sequence; | |
47 } | |
48 | |
90 | 49 sub dump_ctor { |
50 my ($self) = @_; | |
51 $self = ref $self || $self; | |
52 | |
53 warn "dumping $self .ctor"; | |
54 warn "$_" foreach @{$cacheCTOR{$self}||[]}; | |
55 } | |
56 | |
49 | 57 sub callCTOR { |
58 my $self = shift; | |
59 my $class = ref $self; | |
60 | |
61 $self->$_(@_) foreach @{$cacheCTOR{$class} || cache_ctor($class)}; | |
62 } | |
63 | |
64 sub superCTOR { | |
65 my $this = shift; | |
66 | |
67 warn "The mehod is deprecated, at " . caller; | |
68 } | |
69 | |
70 sub toString { | |
71 my $self = shift; | |
72 | |
73 return (ref $self || $self); | |
74 } | |
75 | |
122 | 76 sub typeof { |
93 | 77 ref $_[0] || $_[0]; |
78 } | |
79 | |
49 | 80 sub isDisposed { |
81 0; | |
82 } | |
83 | |
84 #sub DESTROY { | |
85 # if ($MemoryLeakProtection and $Cleanup) { | |
86 # my $this = shift; | |
87 # warn sprintf("Object leaks: %s of type %s %s",$this->can('ToString') ? $this->ToString : $this,ref $this,UNIVERSAL::can($this,'_dump') ? $this->_dump : ''); | |
88 # } | |
89 #} | |
90 | |
91 sub END { | |
92 $Cleanup = 1; | |
93 } | |
94 | |
95 sub _pass_throgh_mapper { | |
96 @_; | |
97 } | |
98 | |
99 sub PassArgs { | |
100 \&_pass_throgh_mapper; | |
101 } | |
102 | |
103 sub PassThroughArgs { | |
104 my $class = shift; | |
105 $class = ref $class || $class; | |
106 no strict 'refs'; | |
107 no warnings 'once'; | |
108 ${"${class}::CTOR"}{$_} = \&_pass_throgh_mapper foreach @{"${class}::ISA"}; | |
109 } | |
110 | |
111 package self; | |
112 | |
113 our $AUTOLOAD; | |
114 sub AUTOLOAD { | |
108 | 115 goto &{caller(). substr $AUTOLOAD,6}; |
49 | 116 } |
117 | |
118 package supercall; | |
119 | |
120 our $AUTOLOAD; | |
121 sub AUTOLOAD { | |
122 my $sub; | |
123 my $methodName = substr $AUTOLOAD,11; | |
124 no strict 'refs'; | |
125 $sub = $_->can($methodName) and $sub->(@_) foreach @{caller().'::ISA'}; | |
126 } | |
127 | |
63
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
49
diff
changeset
|
128 1; |
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
49
diff
changeset
|
129 |
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
49
diff
changeset
|
130 __END__ |
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
49
diff
changeset
|
131 |
49 | 132 =pod |
63
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
49
diff
changeset
|
133 =head1 SYNOPSIS |
49 | 134 |
135 package MyBaseObject; | |
136 use base qw(IMPL::Object::Abstract); | |
137 | |
138 sub new { | |
139 # own implementation of the new opeator | |
140 } | |
141 | |
142 sub surrogate { | |
143 # own implementation of the surrogate operator | |
144 } | |
145 | |
63
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
49
diff
changeset
|
146 =head1 DESCRIPTION |
49 | 147 |
148 Реализация механизма вызова конструкторов и других вспомогательных вещей, кроме операторов | |
149 создания экземпляров. | |
150 =cut |