[Catalyst-dev] [OT] suggestion to augment the default view
John Napiorkowski
jjn1056 at yahoo.com
Wed Sep 6 15:54:05 CEST 2006
I was also thinking this could be a renderview class
to act as a post operation. This is starting to sound
like a better idea now that you tell me about the
changes for the next version.
Maybe this is a silly question but can you have more
than one renderview class per method? Because I am
thinking of a couple of these I could use. I guess I
could write a class to contain several if not...
Oh, and does anyone know of a way to use an
actionclass to force an action to fail to match? What
I am trying to do is create a neater way to handle my
REST based actions. Right now I do something like:
sub members :Chained CaptureArgs(0)
{
my ($self, $c) = @_;
my $c->stash->{members} = $c->model('db:members');
$c->detach('add') if($c->request->method eq 'POST');
}
sub list :Chained('members') Args(0)
{
## Get the members resultset and forward to view.
}
sub add :Private
{
## validate and update database or return errors.
}
What I think would be cool is if I could do:
sub members :Chained CaptureArgs(0)
{
my ($self, $c) = @_;
my $c->stash->{members} = $c->model('db:members');
}
sub list :Chained('members') Args(0) Methods('GET')
{
## Get the members resultset and forward to view.
}
sub add :Chained('members') Args(0) Methods('POST')
{
## validate and update database or return errors.
}
I realize I'm missing some PathParts here, but I'm
sure you get the idea. I can't see how to do this
with an action class though.
--john
--- Matt S Trout <dbix-class at trout.me.uk> wrote:
> John Napiorkowski wrote:
> > Hi,
> >
> > Right now when you forward to a view without any
> > parameters ($c->view) the default is to either use
> a
> > config setting or to just forward to a single view
> if
> > there is only one view in the list. That's how
> it's
> > documented although I find the behavior is that if
> it
> > finds several views it seems to return the first
> one
> > returned based on some internal sorting order.
>
> Current proposal is to add a check on
> $c->stash->{current_view} before it
> looks for $c->config->{default_view}
>
> If neither is present it should be an error, not
> "return first found"; this is
> a bug that we'll be fixing soon.
>
> > I propose we augment this behavior to add some
> rules
> > to how it matches when there are more than one
> view
> > component. This issue comes to me because I find
> that
> > I tend to make a lot of custom views based on the
> > controller action name. I do this because I
> prefer to
> > move the creation of objects for rendering to the
> > response body to the View directory so that I can
> keep
> > my controllers clean and focused on dispatching
> tasks.
> >
> > The Template Toolkit view has a very sane approach
> to
> > automatically look for a template based on the
> action
> > name. I'm guessing this is a defacto standard for
> a
> > lot of people. What I am thinking is that the
> > $c->view should model it's default behavior in a
> > similar way, that is if you $c->forward($c->view)
> it
> > should forward to a view component that is
> patterned
> > off the algorithm used by the TT view.
> >
> > For example:
> >
> > /C
> > feeds->all :Local
> > feeds->new :Local
> > feeds->popular :Local
> > /V
> > /feeds
> > all.pm
> > new.pm
> > popular.pm
> >
> > So if you called "/feeds/all" the default view
> would
> > be /feeds/all.pm and so forth.
>
> Interesting concept, but I wonder if it might not be
> better as part of
> RenderView than as part of the core?
>
> --
> Matt S Trout Offering custom
> development, consultancy and support
> Technical Director contracts for Catalyst,
> DBIx::Class and BAST. Contact
> Shadowcat Systems Ltd. mst (at)
> shadowcatsystems.co.uk for more information
>
> + Help us build a better perl ORM:
> http://dbix-class.shadowcatsystems.co.uk/ +
>
> _______________________________________________
> Catalyst-dev mailing list
> Catalyst-dev at lists.rawmode.org
>
http://lists.rawmode.org/mailman/listinfo/catalyst-dev
>
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
More information about the Catalyst-dev
mailing list