1 # Copyright © 2002 Adam Heath <doogie@debian.org>
2 # Copyright © 2012-2013 Guillem Jover <guillem@debian.org>
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <https://www.gnu.org/licenses/>.
21 Dpkg::Exit - program exit handlers
25 The Dpkg::Exit module provides support functions to run handlers on exit.
29 package Dpkg
::Exit
2.00;
40 use Exporter
qw(import);
48 =item push_exit_handler($func)
50 Register a code reference into the exit function handlers stack.
54 sub push_exit_handler
{
57 _setup_exit_handlers
() if @handlers == 0;
58 push @handlers, $func;
61 =item pop_exit_handler()
63 Pop the last registered exit handler from the handlers stack.
67 sub pop_exit_handler
{
68 _reset_exit_handlers
() if @handlers == 1;
72 =item run_exit_handlers()
74 Run the registered exit handlers.
78 sub run_exit_handlers
{
79 while (my $handler = pop @handlers) {
82 _reset_exit_handlers
();
90 my @SIGNAMES = qw(INT HUP QUIT);
93 sub _setup_exit_handlers
95 foreach my $signame (@SIGNAMES) {
96 $SIGOLD{$signame} = $SIG{$signame};
97 $SIG{$signame} = \
&_exit_handler
;
101 sub _reset_exit_handlers
103 foreach my $signame (@SIGNAMES) {
104 $SIG{$signame} = $SIGOLD{$signame};
117 =head2 Version 2.00 (dpkg 1.20.0)
119 Hide variable: @handlers.
121 =head2 Version 1.01 (dpkg 1.17.2)
123 New functions: push_exit_handler(), pop_exit_handler(), run_exit_handlers()
125 Deprecated variable: @handlers
127 =head2 Version 1.00 (dpkg 1.15.6)
129 Mark the module as public.