Mercurial > pub > Impl
comparison lib/IMPL/Object/Disposable.pm @ 407:c6e90e02dd17 ref20150831
renamed Lib->lib
| author | cin |
|---|---|
| date | Fri, 04 Sep 2015 19:40:23 +0300 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 406:f23fcb19d3c1 | 407:c6e90e02dd17 |
|---|---|
| 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; |
