summaryrefslogtreecommitdiffstats
path: root/MDK
diff options
context:
space:
mode:
authorPascal Rigaux <pixel@mandriva.com>2001-12-20 12:47:14 +0000
committerPascal Rigaux <pixel@mandriva.com>2001-12-20 12:47:14 +0000
commitb3762a83bd205002bb53e7af0d1130f26c58719c (patch)
treec6fb88aabf40eaa7c120fe8c5b8b7cf6119fdce7 /MDK
parentd9fcecf3ec79c33544662517e4135e1afa10f6af (diff)
downloadperl-MDK-Common-b3762a83bd205002bb53e7af0d1130f26c58719c.tar
perl-MDK-Common-b3762a83bd205002bb53e7af0d1130f26c58719c.tar.gz
perl-MDK-Common-b3762a83bd205002bb53e7af0d1130f26c58719c.tar.bz2
perl-MDK-Common-b3762a83bd205002bb53e7af0d1130f26c58719c.tar.xz
perl-MDK-Common-b3762a83bd205002bb53e7af0d1130f26c58719c.zip
add Various::noreturn()
Diffstat (limited to 'MDK')
-rw-r--r--MDK/Common/Various.pm20
1 files changed, 20 insertions, 0 deletions
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;