[Catalyst] Forward on to other actions after removing first path
segment?
Ben van Staveren
benvanstaveren at gmail.com
Mon Nov 15 12:00:26 GMT 2010
You want chained actions.
package MyApp;
sub _date :Chained('/') CaptureArgs(1) PathPart('date') {
my $self = shift;
my $c = shift;
my $date = shift;
$c->detach('invalid_date') unless($date =~ /^\d{4}-\d{2}-\d{2}/);
$c->stash->{date} = $date;
}
sub something_using_the_date :Chained('/date')
PathPart('something_using_the_date') {
my $self = shift;
my $c = shift;
$c->res->body("Hi, you were looking for date: " . $c->stash->{date});
}
Dorian Taylor (Lists) wrote:
> Hi all,
>
> Suppose I want to have the first path match a pattern, like an
> ISO-8601 date. I then want to chop it out of the URI path and stash it
> and forward the request on to another handler in the fashion of
> mod_perl's $r->internal_redirect. Consider:
>
> package MyApp;
>
> sub _date :Regex('^(\d{4}-\d{2}-\d{2})$') {
> my ($self, $c, @args) = @_;
> $c->stash->{date} = $c->req->captures->[0];
> # OK now what goes here?
> }
>
> I'm ambiguous on two things:
>
> 1) I don't understand why an outside request to /foo will find its way
> to /foo/index in MyApp::Foo but a forwarded request will not. I
> understand I'm supposed to use 'visit' or 'go' but they don't seem to
> do it either.
> 2) I'm not entirely sure about the 'right' way to get the rest of the
> request-URI path. As a (.*) in the regex function attribute? Some
> other way?
>
> Again, my desired effect is to process the rest of the URI path as if
> it was an outside request, after chopping off the first path segment
> and stashing it (if it matches a date).
>
> Insights?
>
> Thanks,
>
> --
> Dorian Taylor
> Make things. Make sense.
> http://doriantaylor.com
>
>
> _______________________________________________
> List: Catalyst at lists.scsys.co.uk
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive:
> http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
> Dev site: http://dev.catalyst.perl.org/
>
--
Ben van Staveren
phone: +62 81 70777529
email: benvanstaveren at gmail.com
More information about the Catalyst
mailing list