[Catalyst] Componentised actions.

Oleg Pronin syber.rus at gmail.com
Thu Mar 29 21:51:33 GMT 2007


I cannot forward to the list actions because they are not private actions
(they have its own URLs). In docs 'forward' is for private actions.
To include their templates i must know the names of templates which is not
good. I want all-in-one action.
Forward to any action of any type (as does dispatcher) but not process full
request cycle (to avoid running the code twice) and insert its body in
requested place.

Sorry my english is not good so i cant fully describe what in my mind :(

This might be useful for including completed components (with logic, view
and model inside) in any website place.
For example you can create url-action which edits some objects and include
it in many templates. This is not like
ordinary template toolkit's include - this component can show itself, modify
data, receive request params etc, like
any web page. And this doesnt depend on whether this action is directly
called from browser or included in some template.

>IMO you shouldn't need to know.
I do need. If action is called from browser then i need to use default VIEW
(with full site design and this template inserted into main area). Otherwise
another 'empty' VIEW should be used which returns only template body itself
without any wrapper. Or i will get 'site in site'.

2007/3/29, Robert 'phaylon' Sedlacek <rs at 474.at>:
>
> Oleg Pronin wrote:
>
> > I'm developing a website based on catalyst and want it to be moduled and
> > componentised the way like this:
> >
> > site.com/object1/list <http://site.com/object1/list>
> >    displays objects 1 in empty design.
> >
> > site.com/object2/list <http://site.com/object2/list>
> >    displays objects 2 in empty design.
>
> Are 'object1' and 'object2' identifiers? Are those objects of the same
> class? If so, try Catalyst::DispatchType::Chained; Example (untested):
>
> package MyApp::Controller::Foo;
> use strict;
> use base 'Catalyst::Controller';
>
> sub load_object : Chained PathPart('object') CaptureArgs(1) {
>      my ($self, $c, $object_id) =3D @_;
>      $c->stash( object =3D> load_object_from_somewhere($object_id);
> }
>
> sub list : Chained('load_object') Args(0) {
>      my ($self, $c) =3D @_;
>      # do something with object
> }
>
> 1;
>
> If those two objects are from a different kind, but share common 'list'
> logic, you can abstract that out into a controller base class and
> inherit the list action in two controllers that provide a load_object
> action.
>
> > site.com/nicepage <http://site.com/nicepage>
> >    displays a page in website design which contains result of processing
> > actions 'site.com/object1/list <http://site.com/object1/list>' and
> > 'site.com/object2/list <http://site.com/object2/list>'.
> >
> > The question one is how do i get the output of the actions inserted into
> > another template ?
> >
> > i mean something like
> >
> > page template page template
> > [% c.forward('/object1/list') %]
> > page template page template,
> >
> > just for example, this of course doesn't work.
>
> Can't you just forward from your nicepage action to the list actions and
> let them prepare resources in the stash? With that, you could just
> include their templates in your template.
>
> > The question two is how do i know while running in '/object2/list'
> action
> > whether action is called from the browser or inserted into another
> template.
>
> IMO you shouldn't need to know. Communicate with the rest of the app via
> the stash. If a template only uses information in the stash (and maybe
> config), it doesn't need to know whether it is the rendered template or
> just an included one.
>
> > I.e. i want URL site.com/object1/list <http://site.com/object1/list> to
> > display information in site design while the same action inserted into
> > another template
> > ( pseudo :) [% c.forward('/object1/list') %] )  to display information
> > in empty desing (i.e. through another VIEW).
>
> What is an 'empty design'? And you probably don't need another View
> either. As said above, I think you should be fine just by separating
> your logic a bit more.
>
> .phaylon
>
> _______________________________________________
> List: Catalyst at lists.rawmode.org
> Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
> Searchable archive:
> http://www.mail-archive.com/catalyst@lists.rawmode.org/
> Dev site: http://dev.catalyst.perl.org/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20070330/6e6c3=
ec9/attachment.htm


More information about the Catalyst mailing list