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