# Copyright (c) 2023 Yuki Kimoto
# MIT License

class Scope::Guard {
  
  use Scope::Guard::Handler;
  
  has handler : ro Scope::Guard::Handler;
  
  static method new : Scope::Guard ($handler : Scope::Guard::Handler) {
    
    unless ($handler) {
      die "\$handler must be defined.";
    }

    my $self = new Scope::Guard;
    
    $self->{handler} = $handler;
    
    return $self;
  }
  
  method DESTROY : void () {
    $self->{handler}->();
  }
}