avoid borging XSLoader errors
[p5sagit/Devel-GlobalDestruction.git] / lib / Devel / GlobalDestruction.pm
CommitLineData
a91e8a78 1#!/usr/bin/perl
2
3package Devel::GlobalDestruction;
4
5use strict;
6use warnings;
7
8use vars qw($VERSION @ISA);
9
10BEGIN {
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
23use 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
36Devel::GlobalDestruction - Expose PL_dirty, the flag which marks global
37destruction.
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
54Perl's global destruction is a little tricky to deal with WRT finalizers
55because it's not ordered and objects can sometimes disappear.
56
57Writing defensive destructors is hard and annoying, and usually if global
58destruction is happenning you only need the destructors that free up non
59process local resources to actually execute.
60
61For these constructors you can avoid the mess by simply bailing out if global
62destruction is in effect.
63
64=head1 EXPORTS
65
66This module uses L<Sub::Exporter> so the exports may be renamed, aliased, etc.
67
68=over 4
69
70=item in_global_destruction
71
72Returns the current value of C<PL_dirty>.
73
74=back
75
76=head1 VERSION CONTROL
77
78This module is maintained using Darcs. You can get the latest version from
79L<http://nothingmuch.woobling.org/code>, and use C<darcs send> to commit
80changes.
81
82=head1 AUTHOR
83
84Yuval 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