When I parse the body of the html response, I want to find the route names for all the links found in the body. I am using the following code snippet:
my $url = Mojo::URL->new( $got );
my $method = uc( $url->query->clone->param( '_method' ) || 'GET' );
my $c = $t->app->build_controller;
my $m = Mojolicious::Routes::Match->new( root => $t->app->routes );
$m->find( $c => { method => $method, path => $url->path } );
Then $m->endpoint->namegives me the name of the route.
But is there an easier way to find the name of the route by the specified path?
I am looking for something like: $app->routes->find( '/api/v/users/146/link/7QRgs' )which should return user_hash_check, because I have the following route:
$guest->get( '/users/:id/link/:hash', 'user_hash_check' )->to( 'user#hash_check' );
source
share