line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/perl |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Callback::Cleanup; |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
31156
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
33
|
|
6
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
27
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
2515
|
use Sub::Clone qw(clone_if_immortal); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use Hash::Util::FieldHash::Compat qw(idhash); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
use Sub::Exporter -setup => { |
13
|
|
|
|
|
|
|
exports => [qw(cleanup callback)], |
14
|
|
|
|
|
|
|
groups => { default => [":all"] }, |
15
|
|
|
|
|
|
|
}; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our $VERSION = "0.03"; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub cleanup (&;$) { |
20
|
|
|
|
|
|
|
my ( $cleanup, $sub ) = @_; |
21
|
|
|
|
|
|
|
$sub ? __PACKAGE__->new( $sub, $cleanup ) : $cleanup; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub callback (&;$) { |
25
|
|
|
|
|
|
|
my ( $sub, $cleanup ) = @_; |
26
|
|
|
|
|
|
|
$cleanup ? __PACKAGE__->new( $sub, $cleanup ) : $sub; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
idhash my %cleanups; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub new { |
32
|
|
|
|
|
|
|
my ( $class, $body, $cleanup ) = @_; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
my $refcounted = clone_if_immortal($body); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
$cleanups{$refcounted} = $cleanup; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
bless $refcounted, $class; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub DESTROY { delete($cleanups{$_[0]})->() } |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
__PACKAGE__; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
__END__ |