annotate Lib/IMPL/Object/Abstract.pm @ 22:da5bc24b3d3c

wmi tests
author Sergey
date Wed, 30 Sep 2009 17:41:32 +0400
parents 78cd38551534
children 7f00786f8210
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
1 package IMPL::Object::Abstract;
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
2 use strict;
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
3 use warnings;
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
4
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
5 use base qw(IMPL::Class::Meta);
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
6
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
7 our $MemoryLeakProtection;
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
8 my $Cleanup = 0;
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
9
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
10 my %cacheCTOR;
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
11
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
12 my $t = 0;
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
13 sub cache_ctor {
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
14 my $class = shift;
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
15
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
16 no strict 'refs';
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
17 my @sequence;
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
18
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
19 my $refCTORS = *{"${class}::CTOR"}{HASH};
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
20
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
21 foreach my $super ( @{"${class}::ISA"} ) {
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
22 my $superSequence = $cacheCTOR{$super} || cache_ctor($super);
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
23
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
24 my $mapper = $refCTORS ? $refCTORS->{$super} : undef;
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
25 if (ref $mapper eq 'CODE') {
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
26 if ($mapper == *_pass_throgh_mapper{CODE}) {
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
27 push @sequence,@$superSequence;
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
28 } else {
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
29 push @sequence, sub {
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
30 my $this = shift;
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
31 $this->$_($mapper->(@_)) foreach @$superSequence;
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
32 };
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
33 }
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
34 } else {
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
35 warn "Unsupported mapper type, in '$class' for the super class '$super'" if $mapper;
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
36 push @sequence, sub {
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
37 my $this = shift;
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
38 $this->$_() foreach @$superSequence;
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
39 };
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
40 }
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
41 }
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
42
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
43 push @sequence, *{"${class}::CTOR"}{CODE} if *{"${class}::CTOR"}{CODE};
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
44
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
45 $cacheCTOR{$class} = \@sequence;
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
46 return \@sequence;
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
47 }
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
48
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
49 sub callCTOR {
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
50 my $self = shift;
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
51 my $class = ref $self;
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
52
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
53 $self->$_(@_) foreach @{$cacheCTOR{$class} || cache_ctor($class)};
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
54 }
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
55
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
56 sub superCTOR {
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
57 my $this = shift;
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
58
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
59 warn "The mehod is deprecated, at " . caller;
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
60 }
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
61
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
62 sub toString {
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
63 my $self = shift;
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
64
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
65 return (ref $self || $self);
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
66 }
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
67
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
68 sub DESTROY {
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
69 if ($MemoryLeakProtection and $Cleanup) {
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
70 my $this = shift;
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
71 warn sprintf("Object leaks: %s of type %s %s",$this->can('ToString') ? $this->ToString : $this,ref $this,UNIVERSAL::can($this,'_dump') ? $this->_dump : '');
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
72 }
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
73 }
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
74
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
75 sub END {
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
76 $Cleanup = 1;
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
77 }
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
78
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
79 sub _pass_throgh_mapper {
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
80 @_;
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
81 }
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
82
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
83 sub PassThroughArgs {
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
84 my $class = shift;
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
85 $class = ref $class || $class;
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
86 no strict 'refs';
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
87 no warnings 'once';
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
88 ${"${class}::CTOR"}{$_} = \&_pass_throgh_mapper foreach @{"${class}::ISA"};
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
89 }
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
90
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
91 package self;
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
92
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
93 our $AUTOLOAD;
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
94 sub AUTOLOAD {
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
95 goto &{caller(). substr $AUTOLOAD,4};
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
96 }
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
97
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
98 package supercall;
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
99
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
100 our $AUTOLOAD;
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
101 sub AUTOLOAD {
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
102 my $sub;
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
103 my $methodName = substr $AUTOLOAD,11;
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
104 no strict 'refs';
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
105 $sub = $_->can($methodName) and $sub->(@_) foreach @{caller().'::ISA'};
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
106 }
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
107
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
108 =pod
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
109 =h1 SYNOPSIS
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
110
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
111 package MyBaseObject;
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
112 use base qw(IMPL::Object::Abstract);
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
113
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
114 sub new {
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
115 # own implementation of the new opeator
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
116 }
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
117
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
118 sub surrogate {
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
119 # own implementation of the surrogate operator
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
120 }
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
121
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
122 =h1 DESCRIPTION
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
123
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
124 Реализация механизма вызова конструкторов и других вспомогательных вещей, кроме операторов
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
125 создания экземпляров.
2
78cd38551534 in develop
Sergey
parents: 1
diff changeset
126 =cut
1
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
127
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
128 1;