From b3762a83bd205002bb53e7af0d1130f26c58719c Mon Sep 17 00:00:00 2001 From: Pascal Rigaux Date: Thu, 20 Dec 2001 12:47:14 +0000 Subject: add Various::noreturn() --- MDK/Common/Various.pm | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'MDK') diff --git a/MDK/Common/Various.pm b/MDK/Common/Various.pm index a8de5fb..0d8f008 100644 --- a/MDK/Common/Various.pm +++ b/MDK/Common/Various.pm @@ -67,6 +67,18 @@ gives oops main::g() called from /tmp/t.pl:2 main::f() called from /tmp/t.pl:4 + +=item noreturn() + +use this to ensure nobody uses the return value of the function. eg: + + sub g { print "g called\n"; noreturn } + sub f { print "g returns ", g() } + f(); + +gives + + test.pl:3: main::f() expects a value from main::g(), but main::g() doesn't return any value =back @@ -107,5 +119,13 @@ sub backtrace { $s; } +sub noreturn { + if (defined wantarray) { + my ($package, $file, $line, $func) = caller(1); + my (undef, undef, undef, $func2) = caller(2); + die "$file:$line: $func2() expects a value from $func(), but $func() doesn't return any value\n"; + } +} + 1; -- cgit v1.2.1