Improve diagnostics and avoid crash with bad arguments.
Lubomir Rintel (Good Data) <lubo.rintel@gooddata.com>
diff -urp Class-MethodMaker-2.12.orig/lib/Class/MethodMaker/Engine.pm Class-MethodMaker-2.12/lib/Class/MethodMaker/Engine.pm
--- Class-MethodMaker-2.12.orig/lib/Class/MethodMaker/Engine.pm 2008-07-20 23:04:43.000000000 +0200
+++ Class-MethodMaker-2.12/lib/Class/MethodMaker/Engine.pm 2008-11-11 00:23:50.000000000 +0100
@@ -778,7 +778,8 @@ sub install_methods {
*{$methname} = $code;
# Generate a unique stash name for the sub. Use a preceding space
# to avoid collisions with anything in the Perl space.
- Class::MethodMaker::set_sub_name($code, $target, $name, "${target}::${name}");
+ croak "Could not create stash name for '$name'"
+ unless Class::MethodMaker::set_sub_name($code, $target, $name, "${target}::${name}");
}
} else {
croak "What do you expect me to do with this?: $code\n";
diff -urp Class-MethodMaker-2.12.orig/MethodMaker.xs Class-MethodMaker-2.12/MethodMaker.xs
--- Class-MethodMaker-2.12.orig/MethodMaker.xs 2008-03-24 21:46:41.000000000 +0100
+++ Class-MethodMaker-2.12/MethodMaker.xs 2008-11-11 00:25:06.000000000 +0100
@@ -4,8 +4,11 @@
MODULE = Class::MethodMaker PACKAGE = Class::MethodMaker
-void
+int
set_sub_name(SV *sub, char *pname, char *subname, char *stashname)
+ INIT:
+ if (!SvTRUE(ST(1)) || !SvTRUE(ST(2)) || !SvTRUE(ST(3)) || !SvTRUE(ST(4)))
+ XSRETURN_UNDEF;
CODE:
CvGV((GV*)SvRV(sub)) = gv_fetchpv(stashname, TRUE, SVt_PV);
GvSTASH(CvGV((GV*)SvRV(sub))) = gv_stashpv(pname, 1);
@@ -15,3 +18,4 @@ set_sub_name(SV *sub, char *pname, char
GvNAME(CvGV((GV*)SvRV(sub))) = savepv(subname);
GvNAMELEN(CvGV((GV*)SvRV(sub))) = strlen(subname);
#endif
+ RETVAL = 1;