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