# Copyright (c) 2023 Yuki Kimoto
# MIT License
class Scope::Guard {
use Scope::Guard::Handler;
has handler : ro Scope::Guard::Handler;
has dismiss : rw byte;
static method new : Scope::Guard ($handler : Scope::Guard::Handler) {
unless ($handler) {
die "The \$handler must be defined";
}
my $self = new Scope::Guard;
$self->{handler} = $handler;
return $self;
}
method DESTROY : void () {
unless ($self->{dismiss}) {
$self->{handler}->();
}
}
}