[Catalyst] Web parts

J. Shirley jshirley at gmail.com
Wed Apr 15 10:59:33 GMT 2009


On Wed, Apr 15, 2009 at 7:41 PM, Kyoko Shikamata
<shikamata at shoeisha.co.jp>wrote:

> Hi,
>
> How do you design web parts ?
>
> I'm using C::P::SubRequest in my project.
>
> Ex:
> <html>
> <body>
>  <div id=3D"main">
>   Hello
>  </div>
>  <div id=3D"right">
>    [% c.subreq('/parts/ranking') %]
>  </div>
> </bod>
> </html>
>
> package MyApp::Controller::Parts::Ranking;
> ......
> sub index : Local {
>    my ( $self, $c ) =3D @_;
>    $c->stash->{data} =3D
>         $c->model('Products')
>         ->search({},
>          {order_by =3D> 'sales DESC' });
>    $c->stash->{template} =3D 'parts/ranking.tt';
>    $c->forward($c->view('TT'));
> }
> 1;
>
> But,
> When I use C::P::PageCache, C::P::SubRequest sometimes is not executed.
> I cannot find the cause.
> So, I'm looking for other methods.
> Pls teach me the good design.
>
>
> I apologize for my poor English.
> ---
> Kyoko Shikamata
>
>
Why are you using a subrequest, rather than forwarding to the controller and
allowing that to populate the stash?  Unless you have a reason for the
subrequest, it is usually better to simply generate all data in the stash,
and have the template render out the data.  So your main controller would
simply do $c->forward('/parts/ranking') and include the template for
processing ([% PROCESS "parts/ranking.tt" %])

SubRequest makes an entirely new request inside, blocking the calling
request until the other is done.  If you want this type of design you
probably should be using Catalyst::View::Component::SubInclude as a
framework, rather than doing it on your own.  The benefits of this are when
you launch, you can use something that supports ESI and cache the entire
page but only call the individual subcomponents.

I do think that your design may be overly complex, but without knowing more
details I cannot help any further.

(I notice you have a .jp email address, so I'll mention that I'll be giving
a Catalyst talk in Akihabara on April 21st, by the way.
http://japan.perlassociation.org/event/jpa-seminar-01 -- the JPA is
translating my slides)

-J
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20090415/07d2b=
28f/attachment.htm


More information about the Catalyst mailing list