Routing Rails or Django in Perl

I'm used to how Rails maps the route, or Django uses regex on the route (I don't expect in Django, but that's what I heard how it does) and how they use the permalinks style to access the particle webpage. Is it possible to do the same in Perl?

+3
source share
2 answers

I think the Perl web infrastructure with most routing like Rails will be Mojolicious

The creator Mojoliciouswrote an excellent blog entry called “Mannequin Manager,” comparing the main Perl, Ruby, and Python framework web pages and emphasizing that he thought there were improvements he made with routing to Mojolicious.

Unfortunately, the above posts are no longer online :( Instead you need to agree to the documentation Mojolicious::Guides::Routing. Here is an example of routing from the docs:

package MyApp;
use base 'Mojolicious';

sub startup {
    my $self = shift;

    # Router
    my $r = $self->routes;

    # Route
    $r->route('/welcome')->to(controller => 'foo', action => 'welcome');
}

1;


There are also other Perl frameworks that provide a direct URL for routing actions:

A more complete list of Perl web frameworks can be found on the Perl5 wiki


, Plack ( . PSGI wikipedia). , Rack Ruby WSGI Python.

Plack:

use 5.012;
use warnings;

my $app = sub {
    my $env = shift;

    given ($env->{PATH_INFO}) {

        return [ 200, [ 'Content-Type' => 'text/plain' ], [ 'Hello Baz!' ] ]
            when '/hello/baz';

        default {
            return [ 200, [ 'Content-Type' => 'text/plain' ], [ 'Hello World' ]];
        }
    }
}

plackup above_script.psgi .

+7
+3

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


All Articles