annotate Lib/IMPL/Object/Abstract.pm @ 115:5edc2ac5231c

minor fix to the serialization mechanism
author wizard
date Wed, 26 May 2010 02:32:22 +0400
parents c6fb6964de4c
children a7efb3117295
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
1 package IMPL::Object::Abstract;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
2 use strict;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
3 use warnings;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
4
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
5 use base qw(IMPL::Class::Meta);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
6
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
7 our $MemoryLeakProtection;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
8 my $Cleanup = 0;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
9
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
10 my %cacheCTOR;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
11
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
12 my $t = 0;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
13 sub cache_ctor {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
14 my $class = shift;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
15
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
16 no strict 'refs';
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
17 my @sequence;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
18
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
19 my $refCTORS = *{"${class}::CTOR"}{HASH};
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
20
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
21 foreach my $super ( @{"${class}::ISA"} ) {
90
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 63
diff changeset
22 my $superSequence = $cacheCTOR{$super} || cache_ctor($super);
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 63
diff changeset
23
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 63
diff changeset
24 my $mapper = $refCTORS ? $refCTORS->{$super} : undef;
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 63
diff changeset
25 if (ref $mapper eq 'CODE') {
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 63
diff changeset
26 if ($mapper == *_pass_throgh_mapper{CODE}) {
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 63
diff changeset
27 push @sequence,@$superSequence;
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 63
diff changeset
28 } else {
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 63
diff changeset
29 push @sequence, sub {
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 63
diff changeset
30 my $this = shift;
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 63
diff changeset
31 $this->$_($mapper->(@_)) foreach @$superSequence;
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 63
diff changeset
32 };
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 63
diff changeset
33 }
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 63
diff changeset
34 } else {
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 63
diff changeset
35 warn "Unsupported mapper type, in '$class' for the super class '$super'" if $mapper;
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 63
diff changeset
36 push @sequence, sub {
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 63
diff changeset
37 my $this = shift;
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 63
diff changeset
38 $this->$_() foreach @$superSequence;
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 63
diff changeset
39 };
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 63
diff changeset
40 }
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
41 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
42
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
43 push @sequence, *{"${class}::CTOR"}{CODE} if *{"${class}::CTOR"}{CODE};
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
44
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
45 $cacheCTOR{$class} = \@sequence;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
46 return \@sequence;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
47 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
48
90
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 63
diff changeset
49 sub dump_ctor {
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 63
diff changeset
50 my ($self) = @_;
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 63
diff changeset
51 $self = ref $self || $self;
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 63
diff changeset
52
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 63
diff changeset
53 warn "dumping $self .ctor";
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 63
diff changeset
54 warn "$_" foreach @{$cacheCTOR{$self}||[]};
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 63
diff changeset
55 }
dc1da0389db7 Small improvements in the abstract object class
wizard
parents: 63
diff changeset
56
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
57 sub callCTOR {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
58 my $self = shift;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
59 my $class = ref $self;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
60
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
61 $self->$_(@_) foreach @{$cacheCTOR{$class} || cache_ctor($class)};
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
62 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
63
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
64 sub superCTOR {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
65 my $this = shift;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
66
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
67 warn "The mehod is deprecated, at " . caller;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
68 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
69
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
70 sub toString {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
71 my $self = shift;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
72
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
73 return (ref $self || $self);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
74 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
75
93
0667064553ef fixed _is_class in activator
wizard
parents: 90
diff changeset
76 sub type {
0667064553ef fixed _is_class in activator
wizard
parents: 90
diff changeset
77 ref $_[0] || $_[0];
0667064553ef fixed _is_class in activator
wizard
parents: 90
diff changeset
78 }
0667064553ef fixed _is_class in activator
wizard
parents: 90
diff changeset
79
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
80 sub isDisposed {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
81 0;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
82 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
83
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
84 #sub DESTROY {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
85 # if ($MemoryLeakProtection and $Cleanup) {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
86 # my $this = shift;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
87 # warn sprintf("Object leaks: %s of type %s %s",$this->can('ToString') ? $this->ToString : $this,ref $this,UNIVERSAL::can($this,'_dump') ? $this->_dump : '');
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
88 # }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
89 #}
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
90
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
91 sub END {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
92 $Cleanup = 1;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
93 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
94
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
95 sub _pass_throgh_mapper {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
96 @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
97 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
98
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
99 sub PassArgs {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
100 \&_pass_throgh_mapper;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
101 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
102
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
103 sub PassThroughArgs {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
104 my $class = shift;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
105 $class = ref $class || $class;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
106 no strict 'refs';
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
107 no warnings 'once';
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
108 ${"${class}::CTOR"}{$_} = \&_pass_throgh_mapper foreach @{"${class}::ISA"};
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
109 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
110
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
111 package self;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
112
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
113 our $AUTOLOAD;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
114 sub AUTOLOAD {
108
c6fb6964de4c Removed absolute modules
wizard
parents: 93
diff changeset
115 goto &{caller(). substr $AUTOLOAD,6};
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
116 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
117
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
118 package supercall;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
119
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
120 our $AUTOLOAD;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
121 sub AUTOLOAD {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
122 my $sub;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
123 my $methodName = substr $AUTOLOAD,11;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
124 no strict 'refs';
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
125 $sub = $_->can($methodName) and $sub->(@_) foreach @{caller().'::ISA'};
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
126 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
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
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
132 =pod
63
76b878ad6596 Added serialization support for the IMPL::Object::List
wizard
parents: 49
diff changeset
133 =head1 SYNOPSIS
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
134
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
135 package MyBaseObject;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
136 use base qw(IMPL::Object::Abstract);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
137
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
138 sub new {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
139 # own implementation of the new opeator
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
140 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
141
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
142 sub surrogate {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
143 # own implementation of the surrogate operator
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
144 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
145
63
76b878ad6596 Added serialization support for the IMPL::Object::List
wizard
parents: 49
diff changeset
146 =head1 DESCRIPTION
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
147
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
148 Реализация механизма вызова конструкторов и других вспомогательных вещей, кроме операторов
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
149 создания экземпляров.
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 33
diff changeset
150 =cut