But, not as for the build-in function caller(), this doesn't work and it throws the following error:my $class = 'MyClass'; *CORE::GLOBAL::wantarray = sub { return CORE::wantarray(@_) if(!${"$class\::PRETEND_CONTEXT"}); return 1 if(${"$class\::PRETEND_CONTEXT"} == 3); return 0 if(${"$class\::PRETEND_CONTEXT"} == 2); return undef if(${"$class\::PRETEND_CONTEXT"} == 1); };
It seems to be, that wantarray isn't in CORE. But where it is? If I only redefine the function (in CORE::GLOBAL::) without calling the original function, all is ok. But I don't want that. How can I decorate it? Any suggestions? Tobiwan PS: if you want to try the code-snippet, you have to put it into the "import()" function of a class and you have to "use TheClass;". There is a write protection for the CORE:: Classes.Bareword found where operator expected at /usr/lib/perl/5.8/Data/Dumpe +r.pm line 267, near "$realtype = $realpack ? Scalar::Util::reftype" (Might be a runaway multi-line ?? string starting on line 237) (Missing operator before Scalar::Util::reftype?)
In reply to Overwrite built-in wantarray() by Tobiwan
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |