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