… | |
… | |
42 | package Guard; |
42 | package Guard; |
43 | |
43 | |
44 | no warnings; |
44 | no warnings; |
45 | |
45 | |
46 | BEGIN { |
46 | BEGIN { |
47 | $VERSION = '1.021'; |
47 | $VERSION = 1.023; |
48 | @ISA = qw(Exporter); |
48 | @ISA = qw(Exporter); |
49 | @EXPORT = qw(guard scope_guard); |
49 | @EXPORT = qw(guard scope_guard); |
50 | |
50 | |
51 | require Exporter; |
51 | require Exporter; |
52 | |
52 | |
… | |
… | |
55 | } |
55 | } |
56 | |
56 | |
57 | our $DIED = sub { warn "$@" }; |
57 | our $DIED = sub { warn "$@" }; |
58 | |
58 | |
59 | =item scope_guard BLOCK |
59 | =item scope_guard BLOCK |
|
|
60 | |
|
|
61 | =item scope_guard ($coderef) |
60 | |
62 | |
61 | Registers a block that is executed when the current scope (block, |
63 | Registers a block that is executed when the current scope (block, |
62 | function, method, eval etc.) is exited. |
64 | function, method, eval etc.) is exited. |
63 | |
65 | |
64 | See the EXCEPTIONS section for an explanation of how exceptions |
66 | See the EXCEPTIONS section for an explanation of how exceptions |
… | |
… | |
102 | |
104 | |
103 | # do something with the new timezone |
105 | # do something with the new timezone |
104 | } |
106 | } |
105 | |
107 | |
106 | =item my $guard = guard BLOCK |
108 | =item my $guard = guard BLOCK |
|
|
109 | |
|
|
110 | =item my $guard = guard ($coderef) |
107 | |
111 | |
108 | Behaves the same as C<scope_guard>, except that instead of executing |
112 | Behaves the same as C<scope_guard>, except that instead of executing |
109 | the block on scope exit, it returns an object whose lifetime determines |
113 | the block on scope exit, it returns an object whose lifetime determines |
110 | when the BLOCK gets executed: when the last reference to the object gets |
114 | when the BLOCK gets executed: when the last reference to the object gets |
111 | destroyed, the BLOCK gets executed as with C<scope_guard>. |
115 | destroyed, the BLOCK gets executed as with C<scope_guard>. |
… | |
… | |
193 | solution to the problem of exceptions. |
197 | solution to the problem of exceptions. |
194 | |
198 | |
195 | =head1 SEE ALSO |
199 | =head1 SEE ALSO |
196 | |
200 | |
197 | L<Scope::Guard> and L<Sub::ScopeFinalizer>, which actually implement |
201 | L<Scope::Guard> and L<Sub::ScopeFinalizer>, which actually implement |
198 | dynamic guards only, not scoped guards, and have a lot higher CPU, memory |
202 | dynamically scoped guards only, not the lexically scoped guards that their |
199 | and typing overhead. |
203 | documentation promises, and have a lot higher CPU, memory and typing |
|
|
204 | overhead. |
200 | |
205 | |
201 | L<Hook::Scope>, which has apparently never been finished and can corrupt |
206 | L<Hook::Scope>, which has apparently never been finished and can corrupt |
202 | memory when used. |
207 | memory when used. |
203 | |
208 | |
|
|
209 | L<Scope::Guard> seems to have a big SEE ALSO section for even more |
|
|
210 | modules like it. |
|
|
211 | |
204 | =cut |
212 | =cut |
205 | |
213 | |