Hello dear esteemed monks,
My toy framework called MVC::Neaf has crawled to 0.20 milestone. EDIT And it's got some misleading method names in it which I would like to correct.
One thing I'm struggling to grasp is how to call requested path's fragments - the part that matched the current controller and whatever follows that path. The current convention is as follows:
- script_name is the part of the path that matched current route, not the name of the script or the raw stuff from PSGI request.
- path_info is anything that follows that matching part, for instance a wiki article name.
- path_info_split is a newer version that takes regular expression capture groups into account.
The overall /EDIT syntax, though still evolving, looks like follows now:
use strict; use warnings; use MVC::Neaf qw(:sugar); get + post '/some/path' => sub { my $req = shift; my $foo = $req->param( foo ); my $bar = $req->param( bar => '\w+' ) # no params w/o validation or die 404; # render a "not found" page my ($from, $to) = $req->path_info_split; $req->script_name; # '/some/path' # frobnicate my $data = frobnicate( $bar, $from .. $to ); return { result => $data, foo => $foo, }; }, default => { -view => 'TT', # JS is the default which generates JSON -template => 'some_file.tt', title => 'My mega new application', version => '0.42', }, param_regex => { foo => '\d+' }, path_info_regex => '(\d+)/(\d+)'; # Hitting /some/path would trigger roughly something like follows # (assuming the controller doesn't die/redirect/stop otherwise) # $my_template->process( 'some_file.tt', { # title => ..., # version => ..., # result => ..., # # whatever else controller returned # } ); neaf->run;
Some working examples exist in the distro.
I know everyone else is using routes of form '/foo/:bar' these days but I don't really like it (although support may be added in the end). The reason is there are a number of formats (:foo, *bar, #baz) and they still don't cover all needed cases ([0-9]+ being the most obvious one).
Now I feel like like these SCRIPT_NAME and PATH_INFO dating back into past century are awkward. My proposal is to rename this stuff completely:
- $req->route() stands for the route that matched (Dancer does like that already).
- $req->suffix() returns the URI capture groups if any were defined.
- suffix => qr/(...)and(...)/ is the corresponding route parameter.
- get '/article/(\d+)/(\d\d)/(\d\d)/(.*)' => ... - I'm also thinking about adding capture groups right into the path (w/o suffix parameter) but that'd be hard to undo so I'm holding it back.
- param => \%spec is the predefined regular expression hash for $req->param( "name" ); (Neaf explicitly forbids unvalidated params and cookies, much like perl -T does).
This scheme looks consistent and clear to me, but maybe I'm missing something. Does that look like a syntax you'd like to try out? What would you like to be added/removed? What is causing surprise and awkwardness here?
Thank you,