Use XSLoader without falling back to DynaLoader
[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 vars qw($VERSION);
a91e8a78 9
53e46d40 10use XSLoader;
a91e8a78 11
53e46d40 12$VERSION = '0.02';
a91e8a78 13
53e46d40 14XSLoader::load(__PACKAGE__, $VERSION);
a91e8a78 15
16use 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
29Devel::GlobalDestruction - Expose PL_dirty, the flag which marks global
30destruction.
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
47Perl's global destruction is a little tricky to deal with WRT finalizers
48because it's not ordered and objects can sometimes disappear.
49
50Writing defensive destructors is hard and annoying, and usually if global
51destruction is happenning you only need the destructors that free up non
52process local resources to actually execute.
53
54For these constructors you can avoid the mess by simply bailing out if global
55destruction is in effect.
56
57=head1 EXPORTS
58
59This module uses L<Sub::Exporter> so the exports may be renamed, aliased, etc.
60
61=over 4
62
63=item in_global_destruction
64
65Returns the current value of C<PL_dirty>.
66
67=back
68
69=head1 VERSION CONTROL
70
71This module is maintained using Darcs. You can get the latest version from
72L<http://nothingmuch.woobling.org/code>, and use C<darcs send> to commit
73changes.
74
75=head1 AUTHOR
76
77Yuval 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