[Catalyst] A View that may include elements optionally returnedfrom other funcs

Carl Johnstone catalyst at fadetoblack.me.uk
Wed Apr 25 11:58:02 GMT 2007

> Ugh...   Assume that the view gets everything from controller.  Then this 
> controller is the thing that should gather everything together before 
> shipping it to the view.  Let the template decide the form, let the 
> controller decide the content.

That's fair enough, but say you've got 20 possible page elements of which 
typically 5 or 6 are included in the final page. Would you still suggest 
that the Controller should initialize any data for all 20 elements onto the 

What if some of those elements are relatively expensive to generate?

What Steve wants is some way of being able to decide in the View which of 
those elements are included and load them accordingly.

The best solution I can come up with is passing coderefs into your view 
which can then be run to retrieve the data would something like this work?

$c->stash->{'get_most_popular'} = sub {
  return $c->model('DB')->some_expensive_db_op();


More information about the Catalyst mailing list