Name
SPVM::Scope::Guard - Executing Handler at End of Scope
Usage
use Scope::Guard;
# Executing the handler at the end of the scope
{
my $guard = Scope::Guard->new(method : void () {
print "End of Scope\n";
});
print "Foo";
}
# With a capture
{
my $value = 1;
my $guard = Scope::Guard->new([$value : int] method : void () {
print "$value\n";
});
print "Foo";
}
Description
Scope::Guard
provides a feature to execue a hander at the end of the scope.
Fields
handler
has handler : ro Scope::Guard::Handler;
A handler. The type is Scope::Guard::Handler.
dismiss
has dismiss : rw byte;
Gets and sets dismiss
field. See the "DESTROY" method about the behavior.
Class Methods
new
static method new : Scope::Guard ($handler : Scope::Guard::Handler)
Creates a new Scope::Guard
object and returns it.
The $handler
is set to the "handler" field.
The $handler
is a Scope::Guard::Handler object.
The $handler
must be defined. Otherwise an exception will be thrown.
Instance Methods
DESTROY
method DESTROY : void ()
Execute the "handler".
If "dismiss" is true, the handler is not executed.
See Also
Scope::Guard
SPVM::Scope::Guard
is a port of Perl's Scope::Guard to SPVM.