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