0
|
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
|
|
12 sub DESTROY {
|
|
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 }
|
33
|
34
|
|
35 sub isDisposed {
|
|
36 1;
|
|
37 }
|
|
38
|
0
|
39 1;
|