SPVM::Scope::Guard - Executing Handler at End of Scope
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"; }
Scope::Guard provides a feature to execue a hander at the end of the scope.
Scope::Guard
has handler : ro Scope::Guard::Handler;
A handler. The type is Scope::Guard::Handler.
has dismiss : rw byte;
Gets and sets dismiss field. See the "DESTROY" method about the behavior.
dismiss
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.
Exceptions:
The $handler must be defined. Otherwize an exception is thrown.
method DESTROY : void ();
Executes the "handler".
If "dismiss" is true, the handler is not executed.
SPVM::Scope::Guard is a port of Perl's Scope::Guard to SPVM.
SPVM::Scope::Guard
Copyright (c) 2023 Yuki Kimoto
MIT License
To install SPVM, copy and paste the appropriate command in to your terminal.
cpanm
cpanm SPVM
CPAN shell
perl -MCPAN -e shell install SPVM
For more information on module installation, please visit the detailed CPAN module installation guide.