407
|
1 package IMPL::Object::Disposable;
|
|
2 use strict;
|
|
3 require IMPL::Object::AutoDispose;
|
|
4
|
|
5 our $Strict = 1;
|
|
6
|
|
7 sub Dispose {
|
|
8 my ($this) = @_;
|
|
9
|
|
10 bless $this, 'IMPL::Object::Disposed';
|
|
11 }
|
|
12
|
|
13 sub DTOR {
|
|
14 my ($this) = @_;
|
|
15
|
|
16 warn sprintf('The object %s were marked as disposable but isn\'t disposed properly', $this->can('ToString') ? $this->ToString() : (ref $this || $this) );
|
|
17 }
|
|
18
|
|
19 sub AutoPtr {
|
|
20 IMPL::Object::AutoDispose->new(shift);
|
|
21 }
|
|
22
|
|
23 package IMPL::Object::Disposed;
|
|
24 our $AUTOLOAD;
|
|
25 sub AUTOLOAD {
|
|
26 return if $AUTOLOAD eq __PACKAGE__.'::DESTROY';
|
|
27 die new IMPL::Exception('Object have been disposed',$AUTOLOAD);
|
|
28 }
|
|
29
|
|
30 sub isDisposed {
|
|
31 1;
|
|
32 }
|
|
33
|
|
34 1;
|