view lib/IMPL/Object/Disposable.pm @ 417:3ed0c58e9da3 ref20150831

working on di container, tests
author cin
date Mon, 02 Nov 2015 01:56:53 +0300
parents c6e90e02dd17
children
line wrap: on
line source

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;