blib/lib/SPVM/Scope/Guard.pm untested

filter: Statementstmt n/a Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a SCAR -
1 package SPVM::Scope::Guard;
2  
3 1;
4  
5 =head1 Name
6  
7 SPVM::Scope::Guard - Executing Callback at End of Scope
8  
9 =head1 Usage
10
11 use Scope::Guard;
12
13 # Executing the callback at the end of the scope
14 {
15 Scope::Guard->new(method : void () {
16 print "End of Scope\n";
17 });
18
19 print "Foo";
20 }
21
22 # With field definitions
23 {
24 my $value = 1;
25 Scope::Guard->new([$value : int] method : void () {
26 print "$value\n";
27 });
28
29 print "Foo";
30 }
31  
32 =head1 Description
33  
34 The Scope::Guard class has the methods to execute a callback at the end of the scope.
35  
36 =head1 Fields
37  
38 =head2 callback
39  
40 C<has callback : ro L<Callback|SPVM::Callback>;>
41  
42 A callback called at the end of the scope.
43  
44 =head1 Class Methods
45  
46 =head2 new
47  
48 C<static method new : L<Scope::Guard|SPVM::Scope::Guard> ($callback : L<Callback|SPVM::Callback>);>
49  
50 Creates a new C<Scope::Guard> object and returns it.
51  
52 $callback is set to L</"callback"> field.
53  
54 Exceptions:
55  
56 $callback must be defined. Otherwise an exception is thrown.
57  
58 =head1 Instance Methods
59  
60 =head2 DESTROY
61  
62 C<method DESTROY : void ();>
63  
64 Executes the L</"callback">.
65  
66 =head1 See Also
67  
68 =head2 Scope::Guard
69  
70 C<SPVM::Scope::Guard> is a port of Perl's L<Scope::Guard> to L<SPVM>.
71  
72 =head1 Copyright & License
73  
74 Copyright (c) 2023 Yuki Kimoto
75  
76 MIT License