Commit | Line | Data |
a91e8a78 |
1 | #!/usr/bin/perl |
2 | |
3 | package Devel::GlobalDestruction; |
4 | |
5 | use strict; |
6 | use warnings; |
7 | |
53e46d40 |
8 | use vars qw($VERSION); |
a91e8a78 |
9 | |
53e46d40 |
10 | use XSLoader; |
a91e8a78 |
11 | |
53e46d40 |
12 | $VERSION = '0.02'; |
a91e8a78 |
13 | |
53e46d40 |
14 | XSLoader::load(__PACKAGE__, $VERSION); |
a91e8a78 |
15 | |
16 | use Sub::Exporter -setup => { |
17 | exports => [ qw(in_global_destruction) ], |
18 | groups => { default => [ -all ] }, |
19 | }; |
20 | |
21 | __PACKAGE__ |
22 | |
23 | __END__ |
24 | |
25 | =pod |
26 | |
27 | =head1 NAME |
28 | |
29 | Devel::GlobalDestruction - Expose PL_dirty, the flag which marks global |
30 | destruction. |
31 | |
32 | =head1 SYNOPSIS |
33 | |
34 | package Foo; |
35 | use Devel::GlobalDestruction; |
36 | |
37 | use namespace::clean; # to avoid having an "in_global_destruction" method |
38 | |
39 | sub DESTROY { |
40 | return if in_global_destruction; |
41 | |
42 | do_something_a_little_tricky(); |
43 | } |
44 | |
45 | =head1 DESCRIPTION |
46 | |
47 | Perl's global destruction is a little tricky to deal with WRT finalizers |
48 | because it's not ordered and objects can sometimes disappear. |
49 | |
50 | Writing defensive destructors is hard and annoying, and usually if global |
51 | destruction is happenning you only need the destructors that free up non |
52 | process local resources to actually execute. |
53 | |
54 | For these constructors you can avoid the mess by simply bailing out if global |
55 | destruction is in effect. |
56 | |
57 | =head1 EXPORTS |
58 | |
59 | This module uses L<Sub::Exporter> so the exports may be renamed, aliased, etc. |
60 | |
61 | =over 4 |
62 | |
63 | =item in_global_destruction |
64 | |
65 | Returns the current value of C<PL_dirty>. |
66 | |
67 | =back |
68 | |
69 | =head1 VERSION CONTROL |
70 | |
71 | This module is maintained using Darcs. You can get the latest version from |
72 | L<http://nothingmuch.woobling.org/code>, and use C<darcs send> to commit |
73 | changes. |
74 | |
75 | =head1 AUTHOR |
76 | |
77 | Yuval Kogman E<lt>nothingmuch@woobling.orgE<gt> |
78 | |
79 | =head1 COPYRIGHT |
80 | |
81 | Copyright (c) 2008 Yuval Kogman. All rights reserved |
82 | This program is free software; you can redistribute |
83 | it and/or modify it under the same terms as Perl itself. |
84 | |
85 | =cut |
86 | |
87 | |