diff Lib/IMPL/Object/Disposable.pm @ 0:03e58a454b20

Создан репозитарий
author Sergey
date Tue, 14 Jul 2009 12:54:37 +0400
parents
children 0004faa276dc
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Lib/IMPL/Object/Disposable.pm	Tue Jul 14 12:54:37 2009 +0400
@@ -0,0 +1,34 @@
+package IMPL::Object::Disposable;
+use strict;
+
+our $Strict = 1;
+
+sub Dispose {
+    my ($this) = @_;
+
+    bless $this, 'IMPL::Object::Disposed';
+}
+
+sub DESTROY {
+    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 superDispose {
+    my ($this) = @_;
+
+    my $package = caller;
+
+    no strict 'refs';
+
+    ($_.'::Dispose')->($this) foreach @{$package.'::ISA'};
+}
+
+package IMPL::Object::Disposed;
+our $AUTOLOAD;
+sub AUTOLOAD {
+    return if $AUTOLOAD eq __PACKAGE__.'::DESTROY';
+    die new IMPL::Exception('Object have been disposed',$AUTOLOAD);
+}
+1;