annotate lib/IMPL/Object/Disposable.pm @ 418:3f38dabaf5cc ref20150831

sync
author cin
date Mon, 28 Dec 2015 15:11:35 +0300
parents c6e90e02dd17
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
407
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
1 package IMPL::Object::Disposable;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
2 use strict;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
3 require IMPL::Object::AutoDispose;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
4
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
5 our $Strict = 1;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
6
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
7 sub Dispose {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
8 my ($this) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
9
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
10 bless $this, 'IMPL::Object::Disposed';
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
11 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
12
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
13 sub DTOR {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
14 my ($this) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
15
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
16 warn sprintf('The object %s were marked as disposable but isn\'t disposed properly', $this->can('ToString') ? $this->ToString() : (ref $this || $this) );
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
17 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
18
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
19 sub AutoPtr {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
20 IMPL::Object::AutoDispose->new(shift);
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
21 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
22
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
23 package IMPL::Object::Disposed;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
24 our $AUTOLOAD;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
25 sub AUTOLOAD {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
26 return if $AUTOLOAD eq __PACKAGE__.'::DESTROY';
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
27 die new IMPL::Exception('Object have been disposed',$AUTOLOAD);
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
28 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
29
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
30 sub isDisposed {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
31 1;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
32 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
33
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
34 1;