Основы работы с маршрутизатором запросов Mojolicious и его основные принципы

Sebastian Riedel (kraih), “Introduction to the Mojolicious router and its underlying concepts”, public translation into Russian from English More about this translation.

Translate into another language.

Participants

r3code748 points
cubloid513 points
Foxcool476 points
And others...
Join Translated.by to translate! If you already have a Translated.by account, please sign in.
If you do not want to register an account, you can sign in with OpenID.
Pages: ← previous Ctrl next
1 2 3 4 5 6 7 8 9 10

Introduction to the Mojolicious router and its underlying concepts

Основы работы с маршрутизатором запросов Mojolicious и его основные принципы

History of edits (Latest: r3code 1 year, 10 months ago) §

# Copyright (C) 2008-2010, Sebastian Riedel.

# Copyright (C) 2008-2010, Sebastian Riedel.

History of edits (Latest: xoma 1 year, 10 months ago) §

=encoding utf8

=encoding utf8

History of edits (Latest: xoma 1 year, 10 months ago) §

=head1 NAME

=head1 НАЗВАНИЕ

History of edits (Latest: xoma 1 year, 10 months ago) §

Mojolicious::Guides::Routing - Routing

Mojolicious::Guides::Routing - Маршрутизация

History of edits (Latest: xoma 1 year, 10 months ago) §

=head1 OVERVIEW

=head1 ОБЗОР

History of edits (Latest: r3code 1 year, 10 months ago) §

This document contains a simple and fun introduction to the L<Mojolicious>
router and its underlying concepts.

Этот документ содержит простое и приятное руководство по работе с маршрутизатором L<Mojolicious> и основные его понятия.

History of edits (Latest: r3code 1 year, 10 months ago) §

— простое и занимательно введение hell yeah!!! (: Foxcool

— :) vti

More 5 comments

— на 8 странице есть абзац про условия, так если писать маршрут "применяется к роутеру" - то выглядит оч криво. r3code

=head1 CONCEPTS

=head1 ПОНЯТИЯ

History of edits (Latest: r3code 1 year, 10 months ago) §

Essentials every L<Mojolicious> developer should know.

Основы, которые должен знать каждый L<Mojolicious> разработчик.

History of edits (Latest: r3code 1 year, 10 months ago) §

— L<Mojolicious> разработчик - если наоборот то относится разработчикам самого Moj r3code

=head2 Dispatcher

=head2 Диспетчер

History of edits (Latest: vti 1 year, 10 months ago) §

The foundation of every web framework is a tiny black box connecting incoming
requests with code generating the appropriate response.

Основой каждого веб фреймворка является небольшой черный ящик, связывающий входящие запросы с кодом, генерующим соответствующий ответ.

History of edits (Latest: cubloid 1 year, 10 months ago) §

GET /user/show/1 -> $self->render(text => 'Sebastian!');

GET /user/show/1 -> $self->render(text => 'Себастьян!');

History of edits (Latest: r3code 1 year, 10 months ago) §

This black box is usually called a dispatcher.
There are many implementations using different strategies to establish these
connections, but pretty much all are based around mapping the requests path
to some kind of response generator.

Этот черный ящик обычно называют диспетчером. Существует множество реализаций, использующих различные подходы для создания таких связей, но практически все, так или иначе, основаны на связывании путей запросов с каким-либо генератором ответа.

History of edits (Latest: r3code 1 year, 10 months ago) §

/user/show/1 -> $self->render(text => 'Sebastian!');
/user/show/2 -> $self->render(text => 'Sara!');
/user/show/3 -> $self->render(text => 'Baerbel!');
/user/show/4 -> $self->render(text => 'Wolfgang!');

/user/show/1 -> $self->render(text => 'Себастьян!');
/user/show/2 -> $self->render(text => 'Сара!');
/user/show/3 -> $self->render(text => 'Беирбел!');
/user/show/4 -> $self->render(text => 'Вольфганг!');

History of edits (Latest: r3code 1 year, 10 months ago) §

While it is very well possible to make all these connections static, it is
also rather inefficient.
Thats why regular expressions are commonly used to make the dispatch process
more dynamic.

Конечно возможно сделать все эти связи статичными, но, безусловно, это не эффективно. По этому часто применяются регулярные выражения, чтобы сделать процесс маршрутизации более динамичным.

History of edits (Latest: r3code 1 year, 10 months ago) §

qr|/user/show/(\d+)| -> $self->render(text => $users{$1});

qr|/user/show/(\d+)| -> $self->render(text => $users{$1});

History of edits (Latest: korshak 1 year, 10 months ago) §

Modern dispatchers have pretty much everything HTTP has to offer at their
disposal and can use many more variables than just the request path, such as
request method and headers like C<Host>, C<User-Agent> and C<Accept>.

В современных диспетчерах есть доступ ко всему, что может предложить HTTP. Можно использовать не только путь запроса, но и, к примеру, метод запроса или заголовки C<Host>, C<User-Agent> и C<Accept>.

History of edits (Latest: cubloid 1 year, 10 months ago) §

GET /user/show/23 HTTP/1.1
Host: mojolicious.org
User-Agent: Mozilla/5.0 (compatible; Mojolicious; Perl)
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

GET /user/show/23 HTTP/1.1
Host: mojolicious.org
User-Agent: Mozilla/5.0 (compatible; Mojolicious; Perl)
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

History of edits (Latest: korshak 1 year, 10 months ago) §

=head2 Routes

=head2 Маршруты

History of edits (Latest: vti 1 year, 10 months ago) §

While regular expressions are quite powerful they also tend to be unpleasant
to look at and are generally overkill for ordinary path matching.

Хотя регулярные выражения достаточно мощное средство, они не очень понятно выглядят и слишком избыточны для простого сопоставления пути.

History of edits (Latest: koban 1 year, 10 months ago) §

— они избыточнЫ koban

— yep! yes! r3code

qr|/user/show/(\d+)| -> $self->render(text => $users{$1});

qr|/user/show/(\d+)| -> $self->render(text => $users{$1});

History of edits (Latest: korshak 1 year, 10 months ago) §

This is where routes come into play, they have been designed from the ground
up to represent paths with placeholders.

Это как раз тот случай, когда можно применить маршруты. Они были спроектированы специально для представления путей со специальными метками (placeholder'ами).

History of edits (Latest: cubloid 1 year, 10 months ago) §
Pages: ← previous Ctrl next
1 2 3 4 5 6 7 8 9 10

© 2008-2010, Sebastian Riedel..