Tobiwan has asked for the wisdom of the Perl Monks concerning the following question:
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?)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Overwrite built-in wantarray()
by merlyn (Sage) on Aug 21, 2007 at 00:03 UTC | |
by Tobiwan (Beadle) on Aug 21, 2007 at 12:19 UTC | |
by merlyn (Sage) on Aug 21, 2007 at 16:53 UTC | |
|
Re: Overwrite built-in wantarray()
by chromatic (Archbishop) on Aug 20, 2007 at 22:48 UTC | |
by almut (Canon) on Aug 20, 2007 at 23:06 UTC |