Last night I played around with dispatching API ideas. Below is some mock POD
for one idea. The summary is:
$self->dispatch([
qr{
/(?#rm) (\w+)
/(?#user) (\w+)
/(?#tags+) ([\w\+]+)
}x;
]);
( A further simplification is in the POD below. )
There is a some proof-of-concept code to go with it at:
http://mark.stosberg.com/perl/dispatch.pl
I've intentionally used the "best practice" of using the "x" modifier to create
something that looks more like a hash than line noise.
I created an implementation of named backreferences to solve this in the
process, which was fun.
RJBS had a different idea, based on a system he uses at work and for Rubric.
His concept is to avoid regex's and provide easy access to process the
PATH_INFO
instead. He might have a run mode that looks like this, if I understand
correctly.
sub bookmarks : Runmode {
my $self = shift;
my $user = $self->unshift_path_info;
my $tags = $self->unshift_path_info;
# ...
}
Actually he said he would further hide the details with his own methods, so the
result
might be simply:
sub bookmarks : Runmode {
my $self = shift;
my $user = $self->get_user;
my @tags = $self->get_tags;
}
Then he is less tied to one URL dispatch scheme in the run mode.
Of course, we don't need to decide on a single best way to do this,
but it's certainly worth discussing the merits of various alternatives.
Opinions from others?
(my sample POD is below)
Mark
=head2 Example of URI to param parsing
So we want:
/bookmarks/markjugg/vegan+recipes
Dispatched to the 'bookmarks' run mode, like this:
$self->bookmarks({user => 'markjugg', tags => [qw/vegan recipes/]});
So we can setup a dispatch table that maps URLS with named backreferences to
run mode names.
# Here we use a hardcoded run mode of 'bookmarks'
$self->dispatch({
qr{
/(?#rm) (\w+)
/(?#user) (\w+)
/(?#tags+) ([\w\+]+)
}x => 'bookmarks',
});
# Here we get the 'rm' from a capture, and use a shorthand in the RE
$self->dispatch([
qr{
/(?#rm) $url_bit
/(?#user) $url_bit
/(?#tags+) $url_bit
}x;
]);
---------------------------------------------------------------------
Web Archive: http://www.mail-archive.com/[email protected]/
http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]