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

Создан репозитарий
author Sergey
date Tue, 14 Jul 2009 12:54:37 +0400
parents
children 0004faa276dc
comparison
equal deleted inserted replaced
-1:000000000000 0:03e58a454b20
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 }
34 1;