Mercurial > pub > Impl
annotate Lib/IMPL/Object/Abstract.pm @ 90:dc1da0389db7
Small improvements in the abstract object class
Added support for a class data, documentation
Additional tests for the new functionality
| author | wizard |
|---|---|
| date | Mon, 26 Apr 2010 03:10:03 +0400 |
| parents | 76b878ad6596 |
| children | 0667064553ef |
| 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; | |
| 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 } | |
| 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 | |
| 76 sub isDisposed { | |
| 77 0; | |
| 78 } | |
| 79 | |
| 80 #sub DESTROY { | |
| 81 # if ($MemoryLeakProtection and $Cleanup) { | |
| 82 # my $this = shift; | |
| 83 # warn sprintf("Object leaks: %s of type %s %s",$this->can('ToString') ? $this->ToString : $this,ref $this,UNIVERSAL::can($this,'_dump') ? $this->_dump : ''); | |
| 84 # } | |
| 85 #} | |
| 86 | |
| 87 sub END { | |
| 88 $Cleanup = 1; | |
| 89 } | |
| 90 | |
| 91 sub _pass_throgh_mapper { | |
| 92 @_; | |
| 93 } | |
| 94 | |
| 95 sub PassArgs { | |
| 96 \&_pass_throgh_mapper; | |
| 97 } | |
| 98 | |
| 99 sub PassThroughArgs { | |
| 100 my $class = shift; | |
| 101 $class = ref $class || $class; | |
| 102 no strict 'refs'; | |
| 103 no warnings 'once'; | |
| 104 ${"${class}::CTOR"}{$_} = \&_pass_throgh_mapper foreach @{"${class}::ISA"}; | |
| 105 } | |
| 106 | |
| 107 package self; | |
| 108 | |
| 109 our $AUTOLOAD; | |
| 110 sub AUTOLOAD { | |
| 111 goto &{caller(). substr $AUTOLOAD,4}; | |
| 112 } | |
| 113 | |
| 114 package supercall; | |
| 115 | |
| 116 our $AUTOLOAD; | |
| 117 sub AUTOLOAD { | |
| 118 my $sub; | |
| 119 my $methodName = substr $AUTOLOAD,11; | |
| 120 no strict 'refs'; | |
| 121 $sub = $_->can($methodName) and $sub->(@_) foreach @{caller().'::ISA'}; | |
| 122 } | |
| 123 | |
|
63
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
49
diff
changeset
|
124 1; |
|
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
49
diff
changeset
|
125 |
|
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
49
diff
changeset
|
126 __END__ |
|
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
49
diff
changeset
|
127 |
| 49 | 128 =pod |
|
63
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
49
diff
changeset
|
129 =head1 SYNOPSIS |
| 49 | 130 |
| 131 package MyBaseObject; | |
| 132 use base qw(IMPL::Object::Abstract); | |
| 133 | |
| 134 sub new { | |
| 135 # own implementation of the new opeator | |
| 136 } | |
| 137 | |
| 138 sub surrogate { | |
| 139 # own implementation of the surrogate operator | |
| 140 } | |
| 141 | |
|
63
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
49
diff
changeset
|
142 =head1 DESCRIPTION |
| 49 | 143 |
| 144 Реализация механизма вызова конструкторов и других вспомогательных вещей, кроме операторов | |
| 145 создания экземпляров. | |
| 146 =cut |
