I want to fake the context for tests. I want to do something like this
FakeContext('void');
my @response = tested_sub();
is(scalar(@response), 0, 'void return');
FakeContext('scalar');
my @response = tested_sub();
is(scalar(@response), 1, 'scalar return');
I only want to fake the context for this one sub-call. All contexts in calls in this tested_sub() should be real and unmodified. When I overwrite the caller() function and change the wantarray-flag, this doesn't have any effect for wantarray().
And I've to decorate ist, because when I overwrite it complete, I can't fake only the first level of my sub-call.
The only (not really god) idea I've is, to overwrite the wantarray() and use caller() to read out the context. But I think this will cause stragne side-effects.
Any ideas? With PadWalker or Devel::Caller I can read out many things, but can I change the context? I don't know (yet).
PS: with CORE::GLOBAL::wantarray I can overwrite the function, but I can't get any referene to the original sub.