Name

SPVM::Scope::Guard - Executing Callback at End of Scope

Usage

# Executing the callback at the end of the scope
{
Scope::Guard->new(method : void () {
print "End of Scope\n";
});
print "Foo";
}
# With field definitions
{
my $value = 1;
Scope::Guard->new([$value : int] method : void () {
print "$value\n";
});
print "Foo";
}

Description

The Scope::Guard class has the methods to execute a callback at the end of the scope.

Fields

callback

has callback : ro Callback;

A callback called at the end of the scope.

Class Methods

new

static method new : Scope::Guard ($callback : Callback);

Creates a new Scope::Guard object and returns it.

$callback is set to "callback" field.

Exceptions:

$callback must be defined. Otherwise an exception is thrown.

Instance Methods

DESTROY

method DESTROY : void ();

Executes the "callback".

See Also

Scope::Guard

SPVM::Scope::Guard is a port of Perl's Scope::Guard to SPVM.

Copyright & License

Copyright (c) 2023 Yuki Kimoto

MIT License