]> Sergey Matveev's repositories - public-inbox.git/blob - lib/PublicInbox/OnDestroy.pm
65ebd7dcf574f5aa72243add2b0df55f355d794a
[public-inbox.git] / lib / PublicInbox / OnDestroy.pm
1 # Copyright (C) 2020 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
3
4 package PublicInbox::OnDestroy;
5
6 sub new {
7         shift; # ($class, $cb, @args)
8         bless [ @_ ], __PACKAGE__;
9 }
10
11 sub DESTROY {
12         my ($cb, @args) = @{$_[0]};
13         if (!ref($cb)) {
14                 my $pid = $cb;
15                 return if $pid != $$;
16                 $cb = shift @args;
17         }
18         $cb->(@args) if $cb;
19 }
20
21 1;