How to find the route name for a given path in Mojolicious?

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' );
+4
source share
1 answer

I found only one place where we can find the route along the way. This is Mojolicious :: Routes :: Match and there is no other way to do it.

, , - Mojolicious::Controller . : . , : conditions

, , , :

find , : . ( )

conditions , . , . . ?

, -

-1

Source: https://habr.com/ru/post/1665752/


All Articles