ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Guard/Guard.pm
(Generate patch)

Comparing Guard/Guard.pm (file contents):
Revision 1.1 by root, Sat Dec 13 17:37:22 2008 UTC vs.
Revision 1.2 by root, Sat Dec 13 17:49:12 2008 UTC

13expected. 13expected.
14 14
15Specifically, this module supports two different types of guards: guard 15Specifically, this module supports two different types of guards: guard
16objects, which execute a given code block when destroyed, and scoped 16objects, which execute a given code block when destroyed, and scoped
17guards, which are tied to the scope exit. 17guards, which are tied to the scope exit.
18
19=head1 FUNCTIONS
20
21This module currently exports the C<scope_guard> and C<guard> functions by
22default.
18 23
19=over 4 24=over 4
20 25
21=cut 26=cut
22 27
38=item scope_guard BLOCK 43=item scope_guard BLOCK
39 44
40Registers a block that is executed when the current scope (block, 45Registers a block that is executed when the current scope (block,
41function, method, eval etc.) is exited. 46function, method, eval etc.) is exited.
42 47
48The description below sounds a bit complicated, but that's just because
49C<scope_guard> tries to get even corner cases "right": the goal is to
50provide you with a rock solid clean up tool.
51
43This is similar to this code fragment: 52This is similar to this code fragment:
44 53
45 eval ... code following scope_guard ... 54 eval ... code following scope_guard ...
46 { 55 {
47 local $@; 56 local $@;
48 eval BLOCK; 57 eval BLOCK;
49 eval { $Guard::DIED->() } if $@; 58 eval { $Guard::DIED->() } if $@;
50 } 59 }
60 die if $@;
51 61
52Except it is much faster, and the whole thing gets executed even when the 62Except it is much faster, and the whole thing gets executed even when the
53BLOCK calls C<exit>, C<goto>, C<last> or escapes via other means. 63BLOCK calls C<exit>, C<goto>, C<last> or escapes via other means.
54 64
55See B<EXCEPTIONS>, below, for an explanation of exception handling 65See B<EXCEPTIONS>, below, for an explanation of exception handling

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines