Commit | Line | Data |
---|---|---|
0111154e Z |
1 | warn "Legacy library @{[(caller(0))[6]]} will be removed from the Perl core distribution in the next major release. Please install it from the CPAN distribution Perl4::CoreLibs. It is being used at @{[(caller)[1]]}, line @{[(caller)[2]]}.\n"; |
2 | ||
870abcc9 S |
3 | # |
4 | # This library is no longer being maintained, and is included for backward | |
5 | # compatibility with Perl 4 programs which may require it. | |
6 | # This legacy library is deprecated and will be removed in a future | |
7 | # release of perl. | |
8 | # | |
f1ca563b LW |
9 | # assert.pl |
10 | # tchrist@convex.com (Tom Christiansen) | |
11 | # | |
12 | # Usage: | |
13 | # | |
14 | # &assert('@x > @y'); | |
15 | # &assert('$var > 10', $var, $othervar, @various_info); | |
16 | # | |
17 | # That is, if the first expression evals false, we blow up. The | |
18 | # rest of the args, if any, are nice to know because they will | |
19 | # be printed out by &panic, which is just the stack-backtrace | |
20 | # routine shamelessly borrowed from the perl debugger. | |
21 | ||
22 | sub assert { | |
859172fe | 23 | &panic("ASSERTION BOTCHED: $_[0]",$@) unless eval $_[0]; |
f1ca563b LW |
24 | } |
25 | ||
26 | sub panic { | |
748a9306 LW |
27 | package DB; |
28 | ||
f1ca563b LW |
29 | select(STDERR); |
30 | ||
31 | print "\npanic: @_\n"; | |
32 | ||
33 | exit 1 if $] <= 4.003; # caller broken | |
34 | ||
35 | # stack traceback gratefully borrowed from perl debugger | |
36 | ||
748a9306 LW |
37 | local $_; |
38 | my $i; | |
39 | my ($p,$f,$l,$s,$h,$a,@a,@frames); | |
f1ca563b | 40 | for ($i = 0; ($p,$f,$l,$s,$h,$w) = caller($i); $i++) { |
748a9306 | 41 | @a = @args; |
f1ca563b LW |
42 | for (@a) { |
43 | if (/^StB\000/ && length($_) == length($_main{'_main'})) { | |
44 | $_ = sprintf("%s",$_); | |
45 | } | |
46 | else { | |
47 | s/'/\\'/g; | |
48 | s/([^\0]*)/'$1'/ unless /^-?[\d.]+$/; | |
49 | s/([\200-\377])/sprintf("M-%c",ord($1)&0177)/eg; | |
50 | s/([\0-\37\177])/sprintf("^%c",ord($1)^64)/eg; | |
51 | } | |
52 | } | |
53 | $w = $w ? '@ = ' : '$ = '; | |
54 | $a = $h ? '(' . join(', ', @a) . ')' : ''; | |
748a9306 | 55 | push(@frames, "$w&$s$a from file $f line $l\n"); |
f1ca563b | 56 | } |
748a9306 LW |
57 | for ($i=0; $i <= $#frames; $i++) { |
58 | print $frames[$i]; | |
f1ca563b LW |
59 | } |
60 | exit 1; | |
61 | } | |
62 | ||
63 | 1; |