in reply to OX and routing: how to declare something like /api/action.:format

My problem is that the /api/action.:format route doesn't seem to match anything.

Turn on debugging :) https://metacpan.org/pod/Path::Router#DEBUGGING

#!/usr/bin/perl -- BEGIN{$ENV{PATH_ROUTER_DEBUG}=999;} use Path::Router; use Path::Router::Shell; my $router = Path::Router->new; $router->add_route( '/api/action.:format' ); $router->add_route( '/ro/sham/:bo' ); Path::Router::Shell->new(router => $router )->shell; __END__ /ro/sham/json Attempting to match /api/action.:format against ro/sham/json regexp +is (?:api(?:\/action.:format)) ... LENGTH DID NOT MATCH Attempting to match /ro/sham/:bo against ro/sham/json regexp is (?:r +o(?:\/sham(?:\/([^\/]+)))) match success $VAR1 = bless( { 'mapping' => { 'bo' => 'json' }, 'route' => bless( { 'validations' => {}, 'components' => [ 'ro', 'sham', ':bo' ], 'defaults' => {}, 'path' => '/ro/sham/:bo' }, 'Path::Router::Route' ), 'path' => 'ro/sham/json' }, 'Path::Router::Route::Match' );

So something something "components" something

What could be a solution to my problem?

MANIFEST :) http://search.cpan.org/dist/OX/MANIFEST, http://search.cpan.org/dist/Path-Router/MANIFEST, http://search.cpan.org/dist/Path-Dispatcher/MANIFEST,
https://metacpan.org/source/DOY/OX-0.13/t/apps/Counter-Over-Engineered-Sugar/lib/Counter/Over/Engineered/Sugar.pm
https://metacpan.org/source/DOY/Path-Router-0.12/t/006_match_w_targets.t
https://metacpan.org/source/DOY/Path-Router-0.12/t/003_messy_paths.t

Hmm, so the dot is the dot dot dot not slash slash slash ... what?

update: I don't see that it can be done (seems to assume / decides what can be :variable ) ... I would consult module author for this bug-or-wishlist item , or try some other router

This is why I think that

#!/usr/bin/perl -- BEGIN{$ENV{PATH_ROUTER_DEBUG}=999;} use Path::Router; use Path::Router::Shell; use Data::Dump qw/ dd pp /; my $router = Path::Router->new; $router->add_route( '/api/action.:format' ); $router->add_route( '/ro/sham/:bo' ); my $route = '/ro/sham/json'; dd( $route => scalar( $router->match( $route ) ) ); dd( $router ); __END__ Attempting to match /api/action.:format against ro/sham/json regexp +is (?:api(?:\/action.:format)) Attempting to match /ro/sham/:bo against ro/sham/json regexp is (?:r +o(?:\/sham(?:\/([^\/]+)))) match success ( "/ro/sham/json", bless({ mapping => { bo => "json" }, path => "ro/sham/json", route => bless({ components => ["ro", "sham", ":bo"], defaults => {}, path => "/ro/sham/:bo", validations => {}, }, "Path::Router::Route"), }, "Path::Router::Route::Match"), ) bless({ inline => 1, match_code => sub { ... }, route_class => "Path::Router::Route", routes => [ bless({ components => ["api", "action.:format"], defaults => {}, path => "/api/action.:format", validations => {}, }, "Path::Router::Route"), bless({ components => ["ro", "sham", ":bo"], defaults => {}, path => "/ro/sham/:bo", validations => {}, }, "Path::Router::Route"), ], }, "Path::Router")

can't fake it, so bug

#!/usr/bin/perl -- BEGIN{$ENV{PATH_ROUTER_DEBUG}=999;} use Path::Router; use Data::Dump qw/ dd pp /; my $router = Path::Router->new; push @{ $router->{routes} }, bless({ components => ["a", "b.", ":c"], defaults => {}, path => "/a/b.:c", validations => { c}, }, "Path::Router::Route"); my $route = 'a/b.json'; dd( $route => scalar( $router->match( $route ) ) ); __END__ Attempting to match /a/b.:c against a/b.json regexp is (?:a(?:\/b.(? +:\/([^\/]+)))) match failed ("a/b.json", undef)

And I'm bored again

  • Comment on Re: OX and routing: how to declare something like /api/action.:format ($DEBUG++ MANIFEST)
  • Select or Download Code

Replies are listed 'Best First'.
Re^2: OX and routing: how to declare something like /api/action.:format ($DEBUG++ MANIFEST)
by mascip (Pilgrim) on Dec 08, 2013 at 16:14 UTC

    Wow, thank you! I never think about checking the tests, good thinking.

    I've found this solution which works:

    my @extensions = ('', '.json', '.yaml'); route "/api/action$_" => 'controller.action' for @extensions;

    It's not elegant but I might figure out a way to make it look nicer in the future.

      :) broooforce naturally :) in a way this is nicer for it makes explicit and discoverable (introspection) of whats available

        That's true, explicit declaration is kind of clean. But if I end up doing this in several projects, then I'll want to make a plugin out of it. I'm not sure how yet. Maybe a role that adds a router_REST function to OX?Adding a keyword would even be better, but I'm not sure how to go about that. (see Post Scriptum at the end of this message)

        At the moment that seems to be OX's biggest weak points: the lack of shared plugins on CPAN. In a way its strength compensates for this: it's easy to leverage CPAN to write your own and plug them to a project. But still...

        PS: So, how to add a keyword? Either it can simply be a function, which has to be declared earlier so that it doesn't need parenthesis (is that right?); I'm not sure how to achieve this with a role. Or one can create a keyword using the pluggable keyword. Unfortunately there seems to be a pretty steep learning curve (any link to a friendly tutorial?). Haha!! I just found Keyword::Simple, I don't know how good or bad that is. It is very new.