.\" Automatically generated by Pod::Man 2.22 (Pod::Simple 3.13)
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" Set up some character translations and predefined strings. \*(-- will
.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
.\" double quote, and \*(R" will give a right double quote. \*(C+ will
.\" give a nicer C++. Capital omega is used to do unbreakable dashes and
.\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
.\" nothing in troff, for use with C<>.
.tr \(*W-
.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
.ie n \{\
. ds -- \(*W-
. ds PI pi
. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
. ds L" ""
. ds R" ""
. ds C` ""
. ds C' ""
'br\}
.el\{\
. ds -- \|\(em\|
. ds PI \(*p
. ds L" ``
. ds R" ''
'br\}
.\"
.\" Escape single quotes in literal strings from groff's Unicode transform.
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.\"
.\" If the F register is turned on, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
.\" entries marked with X<> in POD. Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.ie \nF \{\
. de IX
. tm Index:\\$1\t\\n%\t"\\$2"
..
. nr % 0
. rr F
.\}
.el \{\
. de IX
..
.\}
.\" ========================================================================
.\"
.IX Title "Scope::Guard 3"
.TH Scope::Guard 3 "2015-07-19" "perl v5.10.1" "User Contributed Perl Documentation"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
.nh
.SH "NAME"
Scope::Guard \- lexically\-scoped resource management
.SH "SYNOPSIS"
.IX Header "SYNOPSIS"
.Vb 1
\& my $guard = guard { ... };
\&
\& # or
\&
\& my $guard = scope_guard \e&handler;
\&
\& # or
\&
\& my $guard = Scope::Guard\->new(sub { ... });
\&
\& $guard\->dismiss(); # disable the handler
.Ve
.SH "DESCRIPTION"
.IX Header "DESCRIPTION"
This module provides a convenient way to perform cleanup or other forms of resource
management at the end of a scope. It is particularly useful when dealing with exceptions:
the \f(CW\*(C`Scope::Guard\*(C'\fR constructor takes a reference to a subroutine that is guaranteed to
be called even if the thread of execution is aborted prematurely. This effectively allows
lexically-scoped \*(L"promises\*(R" to be made that are automatically honoured by perl's garbage
collector.
.PP
For more information, see: <http://www.drdobbs.com/cpp/184403758>
.SH "METHODS"
.IX Header "METHODS"
.SS "new"
.IX Subsection "new"
.Vb 1
\& my $guard = Scope::Guard\->new(sub { ... });
\&
\& # or
\&
\& my $guard = Scope::Guard\->new(\e&handler);
.Ve
.PP
The \f(CW\*(C`new\*(C'\fR method creates a new \f(CW\*(C`Scope::Guard\*(C'\fR object which calls the supplied handler when its \f(CW\*(C`DESTROY\*(C'\fR method is
called, typically at the end of the scope.
.SS "dismiss"
.IX Subsection "dismiss"
.Vb 1
\& $guard\->dismiss();
\&
\& # or
\&
\& $guard\->dismiss(1);
.Ve
.PP
\&\f(CW\*(C`dismiss\*(C'\fR detaches the handler from the \f(CW\*(C`Scope::Guard\*(C'\fR object. This revokes the \*(L"promise\*(R" to call the
handler when the object is destroyed.
.PP
The handler can be re-enabled by calling:
.PP
.Vb 1
\& $guard\->dismiss(0);
.Ve
.SH "EXPORTS"
.IX Header "EXPORTS"
.SS "guard"
.IX Subsection "guard"
\&\f(CW\*(C`guard\*(C'\fR takes a block and returns a new \f(CW\*(C`Scope::Guard\*(C'\fR object. It can be used
as a shorthand for:
.PP
.Vb 1
\& Scope::Guard\->new(...)
.Ve
.PP
e.g.
.PP
.Vb 1
\& my $guard = guard { ... };
.Ve
.PP
Note: calling \f(CW\*(C`guard\*(C'\fR anonymously, i.e. in void context, will raise an exception.
This is because anonymous guards are destroyed \fBimmediately\fR
(rather than at the end of the scope), which is unlikely to be the desired behaviour.
.SS "scope_guard"
.IX Subsection "scope_guard"
\&\f(CW\*(C`scope_guard\*(C'\fR is the same as \f(CW\*(C`guard\*(C'\fR, but it takes a code ref rather than a block.
e.g.
.PP
.Vb 1
\& my $guard = scope_guard \e&handler;
.Ve
.PP
or:
.PP
.Vb 1
\& my $guard = scope_guard sub { ... };
.Ve
.PP
or:
.PP
.Vb 1
\& my $guard = scope_guard $handler;
.Ve
.PP
As with \f(CW\*(C`guard\*(C'\fR, calling \f(CW\*(C`scope_guard\*(C'\fR in void context will raise an exception.
.SH "VERSION"
.IX Header "VERSION"
0.21
.SH "SEE ALSO"
.IX Header "SEE ALSO"
.IP "\(bu" 4
B::Hooks::EndOfScope
.IP "\(bu" 4
End
.IP "\(bu" 4
Guard
.IP "\(bu" 4
Hook::Scope
.IP "\(bu" 4
Object::Destroyer
.IP "\(bu" 4
Perl::AtEndOfScope
.IP "\(bu" 4
ReleaseAction
.IP "\(bu" 4
Scope::local_OnExit
.IP "\(bu" 4
Scope::OnExit
.IP "\(bu" 4
Sub::ScopeFinalizer
.IP "\(bu" 4
Value::Canary
.SH "AUTHOR"
.IX Header "AUTHOR"
chocolateboy <chocolate@cpan.org>
.SH "COPYRIGHT"
.IX Header "COPYRIGHT"
Copyright (c) 2005\-2015, chocolateboy.
.PP
This module is free software. It may be used, redistributed and/or modified under the same terms
as Perl itself.
Copyright 2K16 - 2K18 Indonesian Hacker Rulez