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.


In reply to What I want to do with that by Tobiwan
in thread Overwrite built-in wantarray() by Tobiwan

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.