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.

Class Methods

new

static method new : Scope::Guard ($handler : Scope::Guard::Handler);

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

$handler is set to the "handler" field.

$handler is a Scope::Guard::Handler object.

Exceptions:

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

Instance Methods

DESTROY

method DESTROY : void ();

Executes the "handler".

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