diff lib/IMPL/Object/Disposable.pm @ 407:c6e90e02dd17 ref20150831

renamed Lib->lib
author cin
date Fri, 04 Sep 2015 19:40:23 +0300
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/IMPL/Object/Disposable.pm	Fri Sep 04 19:40:23 2015 +0300
@@ -0,0 +1,34 @@
+package IMPL::Object::Disposable;
+use strict;
+require IMPL::Object::AutoDispose;
+
+our $Strict = 1;
+
+sub Dispose {
+    my ($this) = @_;
+
+    bless $this, 'IMPL::Object::Disposed';
+}
+
+sub DTOR {
+    my ($this) = @_;
+
+    warn sprintf('The object %s were marked as disposable but isn\'t disposed properly', $this->can('ToString') ? $this->ToString() : (ref $this || $this) );
+}
+
+sub AutoPtr {
+    IMPL::Object::AutoDispose->new(shift);
+}
+
+package IMPL::Object::Disposed;
+our $AUTOLOAD;
+sub AUTOLOAD {
+    return if $AUTOLOAD eq __PACKAGE__.'::DESTROY';
+    die new IMPL::Exception('Object have been disposed',$AUTOLOAD);
+}
+
+sub isDisposed {
+    1;
+}
+
+1;