PHP 8.5.2
Preview: Exit.pm Size: 2.42 KB
//usr/share/perl5/Dpkg/Exit.pm

# Copyright © 2002 Adam Heath <doogie@debian.org>
# Copyright © 2012-2013 Guillem Jover <guillem@debian.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.

=encoding utf8

=head1 NAME

Dpkg::Exit - program exit handlers

=head1 DESCRIPTION

The Dpkg::Exit module provides support functions to run handlers on exit.

=cut

package Dpkg::Exit 2.00;

use strict;
use warnings;

our @EXPORT_OK = qw(
    push_exit_handler
    pop_exit_handler
    run_exit_handlers
);

use Exporter qw(import);

my @handlers = ();

=head1 FUNCTIONS

=over 4

=item push_exit_handler($func)

Register a code reference into the exit function handlers stack.

=cut

sub push_exit_handler {
    my ($func) = shift;

    _setup_exit_handlers() if @handlers == 0;
    push @handlers, $func;
}

=item pop_exit_handler()

Pop the last registered exit handler from the handlers stack.

=cut

sub pop_exit_handler {
    _reset_exit_handlers() if @handlers == 1;
    pop @handlers;
}

=item run_exit_handlers()

Run the registered exit handlers.

=cut

sub run_exit_handlers {
    while (my $handler = pop @handlers) {
        $handler->();
    }
    _reset_exit_handlers();
}

sub _exit_handler {
    run_exit_handlers();
    exit(127);
}

my @SIGNAMES = qw(INT HUP QUIT);
my %SIGOLD;

sub _setup_exit_handlers
{
    foreach my $signame (@SIGNAMES) {
        $SIGOLD{$signame} = $SIG{$signame};
        $SIG{$signame} = \&_exit_handler;
    }
}

sub _reset_exit_handlers
{
    foreach my $signame (@SIGNAMES) {
        $SIG{$signame} = $SIGOLD{$signame};
    }
}

END {
    local $?;
    run_exit_handlers();
}

=back

=head1 CHANGES

=head2 Version 2.00 (dpkg 1.20.0)

Hide variable: @handlers.

=head2 Version 1.01 (dpkg 1.17.2)

New functions: push_exit_handler(), pop_exit_handler(), run_exit_handlers()

Deprecated variable: @handlers

=head2 Version 1.00 (dpkg 1.15.6)

Mark the module as public.

=cut

1;

Directory Contents

Dirs: 11 × Files: 30

Name Size Perms Modified Actions
Build DIR
- drwxr-xr-x 2026-01-23 09:00:34
Edit Download
Changelog DIR
- drwxr-xr-x 2026-01-23 09:00:34
Edit Download
- drwxr-xr-x 2026-01-23 09:00:34
Edit Download
Control DIR
- drwxr-xr-x 2026-01-23 09:00:34
Edit Download
Deps DIR
- drwxr-xr-x 2026-01-23 09:00:34
Edit Download
Dist DIR
- drwxr-xr-x 2026-01-23 09:00:34
Edit Download
Interface DIR
- drwxr-xr-x 2026-01-23 09:00:34
Edit Download
OpenPGP DIR
- drwxr-xr-x 2026-01-23 09:00:34
Edit Download
Shlibs DIR
- drwxr-xr-x 2026-01-23 09:00:34
Edit Download
Source DIR
- drwxr-xr-x 2026-01-23 09:00:34
Edit Download
Vendor DIR
- drwxr-xr-x 2026-01-23 09:00:34
Edit Download
14.76 KB lrw-r--r-- 2025-09-18 17:43:59
Edit Download
3.33 KB lrw-r--r-- 2025-09-18 17:43:59
Edit Download
2.23 KB lrw-r--r-- 2025-09-18 17:43:59
Edit Download
14.42 KB lrw-r--r-- 2025-09-18 17:43:59
Edit Download
3.07 KB lrw-r--r-- 2025-09-18 17:43:59
Edit Download
6.20 KB lrw-r--r-- 2025-09-18 17:43:59
Edit Download
3.93 KB lrw-r--r-- 2025-09-18 17:43:59
Edit Download
2.13 KB lrw-r--r-- 2025-09-18 17:43:59
Edit Download
6.02 KB lrw-r--r-- 2025-09-18 17:43:59
Edit Download
20.46 KB lrw-r--r-- 2025-09-18 17:43:59
Edit Download
11.04 KB lrw-r--r-- 2025-09-18 17:43:59
Edit Download
11.94 KB lrw-r--r-- 2025-09-18 17:43:59
Edit Download
5.77 KB lrw-r--r-- 2025-09-18 17:43:59
Edit Download
7.67 KB lrw-r--r-- 2025-09-18 17:43:59
Edit Download
14.76 KB lrw-r--r-- 2025-09-18 17:43:59
Edit Download
5.60 KB lrw-r--r-- 2025-09-18 17:43:59
Edit Download
2.42 KB lrw-r--r-- 2025-09-18 17:43:59
Edit Download
2.06 KB lrw-r--r-- 2025-09-18 17:43:59
Edit Download
1.52 KB lrw-r--r-- 2025-09-18 17:43:59
Edit Download
5.31 KB lrw-r--r-- 2025-09-18 17:43:59
Edit Download
11.41 KB lrw-r--r-- 2025-09-18 17:43:59
Edit Download
11.60 KB lrw-r--r-- 2025-09-18 17:43:59
Edit Download
2.12 KB lrw-r--r-- 2025-09-18 17:43:59
Edit Download
3.99 KB lrw-r--r-- 2025-09-18 17:43:59
Edit Download
2.22 KB lrw-r--r-- 2025-09-18 17:43:59
Edit Download
8.70 KB lrw-r--r-- 2025-09-18 17:43:59
Edit Download
5.69 KB lrw-r--r-- 2025-09-18 17:43:59
Edit Download
11.72 KB lrw-r--r-- 2025-09-18 17:43:59
Edit Download
8.73 KB lrw-r--r-- 2025-09-18 17:43:59
Edit Download
12.86 KB lrw-r--r-- 2025-09-18 17:43:59
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).