1Scope::Guard(3)       User Contributed Perl Documentation      Scope::Guard(3)
2
3
4

NAME

6       Scope::Guard - lexically scoped resource management
7

SYNOPSIS

9               my $sg = Scope::Guard->new(sub { ... });
10
11                 # or
12
13               my $sg = Scope::Guard->new(\&handler);
14
15               $sg->dismiss(); # disable the handler
16

DESCRIPTION

18       This module provides a convenient way to perform cleanup or other forms
19       of resource management at the end of a scope. It is particularly useful
20       when dealing with exceptions: the Scope::Guard constructor takes a ref‐
21       erence to a subroutine that is guaranteed to be called even if the
22       thread of execution is aborted prematurely. This effectively allows
23       lexically-scoped "promises" to be made that are automatically honoured
24       by perl's garbage collector.
25
26       For more information, see: <http://www.cuj.com/documents/s=8000/cujc
27       exp1812alexandr/>
28
29       new
30
31       usage
32
33           my $sg = Scope::Guard->new(sub { ... });
34
35                 # or
36
37           my $sg = Scope::Guard->new(\&handler);
38
39       description
40
41       Create a new Scope::Guard object which calls the supplied handler when
42       its "DESTROY" method is called, typically when it goes out of scope.
43
44       dismiss
45
46       usage
47
48           $sg->dismiss();
49
50                 # or
51
52           $sg->dismiss(1);
53
54       description
55
56       Detach the handler from the Scope::Guard object. This revokes the
57       "promise" to call the handler when the object is destroyed.
58
59       The handler can be re-enabled by calling:
60
61               $sg->dismiss(0);
62

VERSION

64       0.03
65

SEE ALSO

67       * Hook::LexWrap
68       * Hook::Scope
69       * Sub::ScopeFinalizer
70       * Object::Destroyer
71

AUTHOR

73       chocolateboy: <chocolate.boy@email.com>
74
76       Copyright (c) 2005-2007, chocolateboy.
77
78       This module is free software. It may be used, redistributed and/or mod‐
79       ified under the same terms as Perl itself.
80
81
82
83perl v5.8.8                       2007-01-07                   Scope::Guard(3)
Impressum