# Copyright (c) 2023 Yuki Kimoto
# MIT License

class Scope::Guard {
  version_from SPVM;

  
  use Callback;
  
  has callback : ro Callback;
  
  static method new : Scope::Guard ($callback : Callback) {
    
    unless ($callback) {
      die "The callback \$callback must be defined.";
    }
    
    my $self = new Scope::Guard;
    
    $self->{callback} = $callback;
    
    return $self;
  }
  
  method DESTROY : void () {
    $self->{callback}->();
  }
}
