Hi Ben, thanks for replying!

On 15-Nov-10, at 4:00 AM, Ben van Staveren wrote:

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});
}


OK, just that my objective is to optionally prepend just the YYYY-MM- DD format. The PathPart attribute looks as if it wants the actual literal value of a path segment (in your example, 'date'). Consider:

Request-URI: /2010-11-15/foo

* MyApp::_date is triggered
* Removes the date from the first path segment and stashes it
* Forwards to MyApp::Foo::index as if it was a fresh request and the date path segment was never there (except it is, in the stash).

The reason why I want to do this is because I also want to be able to access /foo (aka MyApp::Foo::index) sans any date in the first path segment, and likewise write everything else as if it was agnostic to this behaviour. Spoken another way:

RewriteRule ^/(\d{4}-\d{2}-\d{2})(.*) /$2 [E=DATE:$1]

Does this behaviour still map to chained actions?


--
Dorian Taylor
Make things. Make sense.
http://doriantaylor.com


_______________________________________________
List: [email protected]
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/[email protected]/
Dev site: http://dev.catalyst.perl.org/

Reply via email to