/usr/share/perl5/Core/Exception.pm is in libopensrs-perl 3.0.0-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 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 | # .Copyright (C) 1999-2002 TUCOWS.com Inc.
# .Created: 11/19/1999
# .Contactid: <admin@opensrs.org>
# .Url: http://www.opensrs.org
# .Originally Developed by:
# Tucows/OpenSRS
# .Authors: Leonid Igolnik,
# Evgeniy Pirogov
#
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 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
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package Core::Exception;
use strict;
#BEGIN {
# *CORE::GLOBAL::die = sub {
# if ($Core::Exception::In_Try) {
# throw('internal', @_);
# } else {
# CORE::die(@_);
# }
# }
#}
use Exporter;
use vars qw ( @ISA @EXPORT );
@ISA = qw ( Exporter );
@EXPORT = qw ( try catch strict_throw throw );
# Set while try block is executed
use vars '$In_Try';
#use Core::Exception;
#
#try {
# print "in try\n";
# throw "ErrorState",{q=>1,e=>2,r=>3};
# throw "ErrorState %s", $file;
# die "crazi fish\n";
# } catch {
# _final => sub { my $Er = shift; print "finally\n";},
# ErrorState => sub { my $Er = shift; print "Catcher\n";},
# _other => sub { my $Er = shift; print "otherwise\n";},
# qr/DBI/is => sub { my $Er = shift; print "DBI Error",$Er->info,"\n";},
# }
#;
sub try (&$) {
my($try, $catchers) = @_;
# Set the flag to indicate that we are inside try block
$In_Try++;
# Try the code.
eval {
#clean old error message
local($SIG{'__DIE__'});
&$try()
};
# Reset the flag
$In_Try--;
my $_error = $@;
my $lE;
if ($_error) { #perl doesn't initialize $! when die in DESTROY
$lE = ref $_error eq 'Core::Exception::Err' ?
$_error : new Core::Exception::Err 0, 'internal', $_error;
undef $@;
}
if (exists $catchers->{'_final'}) {
my $finally = $catchers->{'_final'};
&$finally($lE);
}
if (defined $lE) {
my $catcher = $catchers->{$lE->name};
unless ($catcher) {
#check regexp catchers at first
my @all_catchers = keys %$catchers;
my $regexp_catcher;
# Check all regexp rules
foreach (grep /^\(\?/, @all_catchers){
next unless $lE->info =~ /$_/;
$catcher = $catchers->{$_};
last;
}
}
$catcher ||= $catchers->{'_other'} unless $lE->strict;
throw($lE) if not defined $catcher;
&$catcher($lE);
} #if
}
sub catch ($) { shift; }
sub throw {
Core::Exception::Err->_throw(0, @_);
}
sub strict_throw {
Core::Exception::Err->_throw(1, @_);
}
1;
package Core::Exception::Err;
use Data::Dumper;
use vars qw($AUTOLOAD);
use Carp qw(croak);
my %fields = (
callstack => undef,
name => undef,
info => undef
);
sub new {
my $class = shift;
$class = ref($class) || $class;
$fields{strict} = shift;
my $name = shift;
$name ||= 'internal';
$fields{'name'} = $name;
my $info = shift;
if (defined $info && not ref $info) {
if (scalar @_ == 0) {
unshift @_, $info;
$info = '%s';
}
$fields{'info'} = sprintf $info, @_;
if ($fields{name} eq 'internal') {
$fields{name} = 'db' if $fields{info} =~ /DBD|DBI/;
}
} else {
$fields{'info'} = $info;
}
{
my $i = 0;
my $callstack;
my ($pkg, $file, $line);
while (($pkg, $file, $line) = caller($i++)) {
next if $pkg =~ /^Core::Exception/;
$callstack.="\n[$$ module:$pkg,file:$file,line:$line] ";
}
$fields{'callstack'} = $callstack;
}
my $self = {
%fields,
};
bless $self, $class;
return $self;
}
sub DESTROY {
# Prevent AUTOLOAD from catching DESTROY
}
sub AUTOLOAD {
my $self = shift;
my $type = ref($self) ||
croak "$self is not an object AUTOLOAD == $AUTOLOAD";
my $name = $AUTOLOAD;
$name =~ s/.*://; # strip fully-qualified portion
unless (exists $self->{$name} ) {
croak "There is no such `$name' field in object of class $type";
}
return $self->{$name};
}
sub dump {
my $self = shift;
my $dump = "Exception:" . $self->name . ($self->strict ? '(strict)' : '') .
"\nCallStack " .
$self->callstack."\n" .
($self->info ? Dumper($self->info) : "");
}
sub _throw {
my ($self, $strict, $obj_or_type, @args) = @_;
my $class;
my $exception;
if (ref $obj_or_type eq 'Core::Exception::Err') {
$exception = $obj_or_type;
} else {
$exception = $self->new($strict, $obj_or_type, @args);
}
if ($Core::Exception::In_Try) {
CORE::die $exception;
} else {
CORE::die $exception->dump;
}
}
1;
|