Context::Handle - A convenient context propagation proxy thingy.
use Context::Handle qw/context_sensitive/; sub wrapping { my $rv = context_sensitive { $some_thing->method(); # anything really }; # you can do anything here $rv->return; # returns the value in the right context # not reached }
This module lets you delegate to another method and return the value without caring about context propagation.
The level of support is tied to what Want does - this module tries to make all the distinctions Want can make fully supported, for example array dereference context, boolean context, etc.
Nothing is exported by default.
This is a convenience shortcut that calls new
new
This method invokes $code in the calling sub's context, and returns an object that saves the return value.
This instance method returns the return value container object. The only useful methods for the RV containers is value, which has a delegator anyway.
value
This returns the value from the rv_container
rv_container
This (ab)uses Want to perform a double return.
Saying
$rv->return;
is just like
return $rv->value;
Incidientially due to the needs of the wrapping layer this module also provides an OO interface to Want, more or less ;-)
All of these methods return boolean values, with respect to the
pseudoboolean context - the right side of && and the left side of || evaulate in boolean context, but still return a meaningful value.
Glob assignment context. I'm not sure how to make the value propagate back once it's been assigned to the glob - it's hard to know what it is without inspecting the slots and that's kinda tricky.
Lvalue assignment
use Sub::Uplevel to hide the wrapping
context arity - Want's count stuff. This can probably be done using @list[0..$x] = (...), but might need to be emulated with eval. See perldoc -f split.
perldoc -f split
Robin Houston for Want and lots of help by email
Yuval Kogman <nothingmuch@woobling.org>
Copyright (c) 2006 the aforementioned authors. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Context::Handle, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Context::Handle
CPAN shell
perl -MCPAN -e shell install Context::Handle
For more information on module installation, please visit the detailed CPAN module installation guide.