Mercurial > pub > Impl
annotate Lib/IMPL/Object/Disposable.pm @ 279:af8af4b8337e
sync
author | sergey |
---|---|
date | Mon, 04 Feb 2013 17:16:45 +0400 |
parents | ad93c9f4dd93 |
children | 63709a4e6da0 |
rev | line source |
---|---|
49 | 1 package IMPL::Object::Disposable; |
2 use strict; | |
3 | |
4 our $Strict = 1; | |
5 | |
6 sub Dispose { | |
7 my ($this) = @_; | |
8 | |
9 bless $this, 'IMPL::Object::Disposed'; | |
10 } | |
11 | |
273
ad93c9f4dd93
+Added support for destructors, (special method named DTOR)
sergey
parents:
49
diff
changeset
|
12 sub DTOR { |
49 | 13 my ($this) = @_; |
14 | |
15 warn sprintf('The object %s were marked as disposable but isn\'t disposed properly', $this->can('ToString') ? $this->ToString() : (ref $this || $this) ); | |
16 } | |
17 | |
18 sub superDispose { | |
19 my ($this) = @_; | |
20 | |
21 my $package = caller; | |
22 | |
23 no strict 'refs'; | |
24 | |
25 ($_.'::Dispose')->($this) foreach @{$package.'::ISA'}; | |
26 } | |
27 | |
28 package IMPL::Object::Disposed; | |
29 our $AUTOLOAD; | |
30 sub AUTOLOAD { | |
31 return if $AUTOLOAD eq __PACKAGE__.'::DESTROY'; | |
32 die new IMPL::Exception('Object have been disposed',$AUTOLOAD); | |
33 } | |
34 | |
35 sub isDisposed { | |
36 1; | |
37 } | |
38 | |
39 1; |