unbuffered output via multiple templates

View: New views
2 Messages — Rating Filter:   Alert me  

unbuffered output via multiple templates

by Todd Harris-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi all -

Quick introduction:  I'm new to Catalys, but I've been reading the
mailing list online for some time.  I finally have a suitable project
and have just started working on it.  The documentation on list so far
have been a great help.

My question:  I'd like to unbuffer output a la $|++.  I thought one
approach might be to have a series of templates per page, rendering
each sequentially, delivering each to the client in turn.

So far I've come across two possible solutions: 1. SubRequest and 2.
View::TT->render.

But it seems that trapping the output of either and writing to STDOUT
closes the request, such that only the first template is rendered and
sent to the browser.

Some pseudo code to illustrate:

sub myaction : Local {
  my $something = $c->subreq('/do_something',{ bar => $c->stash->{bar} });
  $c->res->body($text);
  $c->res->write($text);

  my $else = $c->subreq('/do_something_else',{ foo => $c->stash->{foo} });
  $c->res->body($else);
  $c->res->write($else);
}

sub do_something : Local {
   my ($self,$c) = @_;
   $c->stash->{load_em_up} = 'here we go';
}

Am I completely off track here?  I've used a monolithic template with
lots of includes but that is not exactly what I would like to
accomplish here.

Thanks in advance for suggestions.

Henri

_______________________________________________
List: Catalyst@...
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@.../
Dev site: http://dev.catalyst.perl.org/

Re: unbuffered output via multiple templates

by Matt S Trout-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Thu, Aug 30, 2007 at 07:22:38PM -0600, Todd Harris wrote:

> Hi all -
>
> Quick introduction:  I'm new to Catalys, but I've been reading the
> mailing list online for some time.  I finally have a suitable project
> and have just started working on it.  The documentation on list so far
> have been a great help.
>
> My question:  I'd like to unbuffer output a la $|++.  I thought one
> approach might be to have a series of templates per page, rendering
> each sequentially, delivering each to the client in turn.
>
> So far I've come across two possible solutions: 1. SubRequest and 2.
> View::TT->render.
>
> But it seems that trapping the output of either and writing to STDOUT
> closes the request, such that only the first template is rendered and
> sent to the browser.

$c->finalize_headers;

foreach my $argset (@argsets) {
  $c->write($c->view($view_name)->render($template, $argset));
}

or code to that effect.

--
      Matt S Trout       Need help with your Catalyst or DBIx::Class project?
   Technical Director    Want a managed development or deployment platform?
 Shadowcat Systems Ltd.  Contact mst (at) shadowcatsystems.co.uk for a quote
http://chainsawblues.vox.com/                    http://www.shadowcat.co.uk/ 

_______________________________________________
List: Catalyst@...
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@.../
Dev site: http://dev.catalyst.perl.org/