Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

What I want to do with that

by Tobiwan (Beadle)
on Aug 21, 2007 at 12:19 UTC ( [id://634062]=note: print w/replies, xml ) Need Help??


in reply to Re: Overwrite built-in wantarray()
in thread Overwrite built-in wantarray()

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.

Replies are listed 'Best First'.
Re: What I want to do with that
by merlyn (Sage) on Aug 21, 2007 at 16:53 UTC
    Ewww. Why not just:
    tested_sub(); ok(some side effect, "expected side effect"); my $scalar_response = tested_sub(); is($scalar_response, $expected, "gives proper scalar value"); my @list_response = tested_sub(); is_deeply(\@list_response,\@expected_response, "gives proper list valu +e");
    Don't be trying to freak Perl out. I'd never expect the right response from giving it the wrong context. That's just asking for hurt.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://634062]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (7)
As of 2024-04-18 07:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found