NAME
YATT::Lite::ConnectionProxy - $CON while capturing output
SYNOPSIS
<!-- Output of the body of <yatt:my> is captured into the variable.
Inside it, $CON methods are still available. -->
<yatt:my tmp>(<yatt:foo/>)</yatt:my>
{&yatt:tmp;}
<!yatt:widget foo>
&yatt:CON:file();
# Generated code (and Perl code) can capture output like this:
my $text = YATT::Lite::ConnectionProxy->capture($CON, sub {
my ($CON) = @_;
print $CON "captured";
$CON->param('q'); # delegated to the original connection
});
DESCRIPTION
When YATT::Lite captures output into a value, the code inside gets a proxy as $CON. This happens for the body of <yatt:my var>...</yatt:my>, elements given to text arguments, and <?perl ?> in such places.
Like YATT::Lite::WebMVC0::Connection, the proxy is a blessed GLOB. Output printed to it goes to the capture buffer. All methods are delegated to the original connection, so param, env, site_path, cookies, session, and others work as usual. can returns a method that works with the proxy, and isa is also true for the classes of the original connection.
Note that methods about the response are delegated too. For example, buffer, flush, raise_redirect and error act on the original response, not on the capture buffer.
METHODS
capture($con, $code)
Calls $code->($proxy) and returns the captured output as a character string.
If $con is already a proxy, the new proxy shares its original connection (no proxy of proxy). If $con is not a YATT::Lite::Connection (eg. a bare filehandle in tests), $code gets a bare filehandle, as YATT::Lite::Util::captured does.
connection
Returns the original connection.