annotate Lib/IMPL/Object/Abstract.pm @ 48:1c3c3e63a314

security in progress
author Sergey
date Fri, 26 Feb 2010 01:43:42 +0300
parents 0004faa276dc
children 16ada169ca75
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
33
0004faa276dc small fixes, some new tests
Sergey
parents: 24
diff changeset
68 sub isDisposed {
0004faa276dc small fixes, some new tests
Sergey
parents: 24
diff changeset
69 0;
1
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
70 }
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
71
33
0004faa276dc small fixes, some new tests
Sergey
parents: 24
diff changeset
72 #sub DESTROY {
0004faa276dc small fixes, some new tests
Sergey
parents: 24
diff changeset
73 # if ($MemoryLeakProtection and $Cleanup) {
0004faa276dc small fixes, some new tests
Sergey
parents: 24
diff changeset
74 # my $this = shift;
0004faa276dc small fixes, some new tests
Sergey
parents: 24
diff changeset
75 # warn sprintf("Object leaks: %s of type %s %s",$this->can('ToString') ? $this->ToString : $this,ref $this,UNIVERSAL::can($this,'_dump') ? $this->_dump : '');
0004faa276dc small fixes, some new tests
Sergey
parents: 24
diff changeset
76 # }
0004faa276dc small fixes, some new tests
Sergey
parents: 24
diff changeset
77 #}
0004faa276dc small fixes, some new tests
Sergey
parents: 24
diff changeset
78
1
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
79 sub END {
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
80 $Cleanup = 1;
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 _pass_throgh_mapper {
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
84 @_;
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
85 }
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
86
24
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 2
diff changeset
87 sub PassArgs {
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 2
diff changeset
88 \&_pass_throgh_mapper;
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 2
diff changeset
89 }
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 2
diff changeset
90
1
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
91 sub PassThroughArgs {
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
92 my $class = shift;
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
93 $class = ref $class || $class;
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
94 no strict 'refs';
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
95 no warnings 'once';
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
96 ${"${class}::CTOR"}{$_} = \&_pass_throgh_mapper foreach @{"${class}::ISA"};
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
97 }
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
98
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
99 package self;
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
100
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
101 our $AUTOLOAD;
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
102 sub AUTOLOAD {
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
103 goto &{caller(). substr $AUTOLOAD,4};
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
104 }
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
105
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
106 package supercall;
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
107
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
108 our $AUTOLOAD;
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
109 sub AUTOLOAD {
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
110 my $sub;
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
111 my $methodName = substr $AUTOLOAD,11;
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
112 no strict 'refs';
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
113 $sub = $_->can($methodName) and $sub->(@_) foreach @{caller().'::ISA'};
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
114 }
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
115
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
116 =pod
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
117 =h1 SYNOPSIS
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
118
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
119 package MyBaseObject;
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
120 use base qw(IMPL::Object::Abstract);
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
121
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
122 sub new {
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
123 # own implementation of the new opeator
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
124 }
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
125
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
126 sub surrogate {
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
127 # own implementation of the surrogate operator
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
128 }
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
129
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
130 =h1 DESCRIPTION
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
131
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
132 ,
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
133 .
2
78cd38551534 in develop
Sergey
parents: 1
diff changeset
134 =cut
1
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
135
3b418b134d8c ORM in progress
Sergey
parents:
diff changeset
136 1;