/usr/share/perl5/UR/Exit.pm is in libur-perl 0.440-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 | package UR::Exit;
=pod
=head1 NAME
UR::Exit - methods to allow clean application exits.
=head1 SYNOPSIS
UR::Exit->exit_handler(\&mysub);
UR::Exit->clean_exit($value);
=head1 DESCRIPTION
This module provides the ability to perform certain operations before
an application exits.
=cut
# set up module
require 5.006_000;
use warnings;
use strict;
require UR;
our $VERSION = "0.44"; # UR $VERSION;;
our (@ISA, @EXPORT, @EXPORT_OK);
require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw();
@EXPORT_OK = qw();
use Carp;
=pod
=head1 METHODS
These methods provide exit functionality.
=over 4
=item exit_handler
UR::Exit->exit_handler(\&mysub);
Specifies that a given subroutine be run when the application exits.
(Unimplimented!)
=cut
sub exit_handler
{
die "Unimplimented";
}
=pod
=item clean_exit
UR::Exit->clean_exit($value);
Exit the application, running all registered subroutines.
(Unimplimented! Just exits the application directly.)
=cut
sub clean_exit
{
my $class = shift;
my ($value) = @_;
$value = 0 unless defined($value);
exit($value);
}
=pod
=item death
Catch any die or warn calls. This is a universal place to catch die
and warn if debugging.
=cut
sub death
{
unless ($ENV{'UR_STACK_DUMP_ON_DIE'}) {
return;
}
# workaround common error
if ($_[0] =~ /Can.*t upgrade that kind of scalar during global destruction/)
{
exit 1;
}
if (defined $^S) {
# $^S is defined when perl is executing (as opposed to interpreting)
if ($^S) {
# $^S is true when its executing in an eval, false outside of one
return;
}
} else {
# interpreter is parsing a module or string eval
# check the call stack depth for up-stream evals
# fall back to perls default handler if there is one
my $call_stack_depth = 0;
for (1) {
my @details = caller($call_stack_depth);
#print Data::Dumper::Dumper(\@details);
last if scalar(@details) == 0;
if ($details[1] =~ /\(eval .*\)/) {
#print "<no carp due to eval string>";
return;
}
elsif ($details[3] eq "(eval)") {
#print "<no carp due to eval block>";
return;
}
$call_stack_depth++;
redo;
}
}
if
(
$_[0] =~ /\n$/
and UNIVERSAL::can("UR::Context::Process","is_initialized")
and defined(UR::Context::Process->is_initialized)
and (UR::Context::Process->is_initialized == 1)
)
{
# Do normal death if there is a newline at the end, and all other
# things are sane.
return;
}
else
{
# Dump the call stack in other cases.
# This is a developer error occurring while things are
# initializing.
local $Carp::CarpLevel = 1;
Carp::confess(@_);
return;
}
}
=pod
=item warning
Give more informative warnings.
=cut
sub warning
{
unless ($ENV{'UR_STACK_DUMP_ON_WARN'}) {
warn @_;
return;
}
return if $_[0] =~ /Attempt to free unreferenced scalar/;
return if $_[0] =~ /Use of uninitialized value in exit at/;
return if $_[0] =~ /Use of uninitialized value in subroutine entry at/;
return if $_[0] =~ /One or more DATA sections were not processed by Inline/;
UR::ModuleBase->warning_message(@_);
if ($_[0] =~ /Deep recursion on subroutine/)
{
print STDERR "Forced exit by UR::Exit on deep recursion.\n";
print STDERR Carp::longmess("Stack tail:");
exit 1;
}
return;
}
#$SIG{__DIE__} = \&death unless ($SIG{__DIE__});
#$SIG{__WARN__} = \&warning unless ($SIG{__WARN__});
sub enable_hooks_for_warn_and_die {
$SIG{__DIE__} = \&death;
$SIG{__WARN__} = \&warning;
}
&enable_hooks_for_warn_and_die();
1;
__END__
=pod
=back
=head1 SEE ALSO
UR(3), Carp(3)
=cut
#$Header$
|