This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
In Perl_sv_gets(), shortbuffered is always 0 when rslen is 0.
[perl5.git] / lib / assert.pl
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
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 #
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 {
23     &panic("ASSERTION BOTCHED: $_[0]",$@) unless eval $_[0];
24
25
26 sub panic {
27     package DB;
28
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
37     local $_;
38     my $i;
39     my ($p,$f,$l,$s,$h,$a,@a,@frames);
40     for ($i = 0; ($p,$f,$l,$s,$h,$w) = caller($i); $i++) {
41         @a = @args;
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) . ')' : '';
55         push(@frames, "$w&$s$a from file $f line $l\n");
56     }
57     for ($i=0; $i <= $#frames; $i++) {
58         print $frames[$i];
59     }
60     exit 1;
61
62
63 1;