Conversation
| has Str $.id is required; | ||
| } | ||
|
|
||
| our $link-plugin is export(:link) = router-plugin-register('link'); |
There was a problem hiding this comment.
Does it have to be our, given we're exporting it?
There was a problem hiding this comment.
[Cro::HTTP] ===SORRY!=== Error while compiling /home/koto/Work/cro/cro-http/lib/Cro/HTTP/Router.pm6 (Cro::HTTP::Router)
[Cro::HTTP] Can't apply trait 'is export' on a my scoped variable. Only our scoped variables are supported.
[Cro::HTTP] at /home/koto/Work/cro/cro-http/lib/Cro/HTTP/Router.pm6 (Cro::HTTP::Router):68
lib/Cro/HTTP/Router.pm6
Outdated
| # my $*CRO-ROUTER-ROUTE-HANDLER = $handler; | ||
| # my %*URLS = $handler ~~ DelegateHandler ?? %() !! router-plugin-get-configs($link-plugin); |
| for $includee.handlers() { | ||
| @!handlers.push: .copy-adding(:@prefix, :@!body-parsers, :@!body-serializers, | ||
| :@!before-matched, :@!after-matched, :@!around, :%!plugin-config); | ||
| my $key = ($name-prefix ?? $name-prefix ~ '.' !! '') ~ ($_.name // ''); |
There was a problem hiding this comment.
Can just be .name here, although I wonder if we really need a key if there is no .name?
There was a problem hiding this comment.
It cannot, here we check if names from our includes (optionally prefixed) are conflicting with each other and with what we have, the checking is bogus if we omit the prefix.
| @!handlers.push: .copy-adding(:@prefix, :@!body-parsers, :@!body-serializers, | ||
| :@!before-matched, :@!after-matched, :@!around, :%!plugin-config); | ||
| my $key = ($name-prefix ?? $name-prefix ~ '.' !! '') ~ ($_.name // ''); | ||
| if $name-prefix && $key && (%urls{$key}:exists) { |
There was a problem hiding this comment.
Why does it matter if we have a $name-prefix here? A conflict of route names in a route block that doesn't itself have a name is still a problem?
There was a problem hiding this comment.
We need it because if the include route ... is anonymous, then we don't have access to its inner names and we don't need to check it for conflicts. Added a comment.
| my $outer-handler = .copy-adding(:@prefix, :@!body-parsers, :@!body-serializers, | ||
| :@!before-matched, :@!after-matched, :@!around, :%!plugin-config, :$name-prefix, :from-include); | ||
| if $outer-handler.name { | ||
| my $link-config = $outer-handler.get-innermost-plugin-configs($link-plugin)[0]; |
There was a problem hiding this comment.
Do we know that the outer handler will always have a config set up?
There was a problem hiding this comment.
Yes, we have a call to generate-urls before this loop and it adds the link plugin state unconditionally.
lib/Cro/HTTP/Router.pm6
Outdated
| } | ||
| @options.push: |$links.link-generators.keys; | ||
| } | ||
| warn "Called the make-link subroutine with $route-name but no such route defined, options are: @options.join('/')"; |
There was a problem hiding this comment.
I don't consider a typo in an url name, which is easy to fix, as something which should crash the whole application.
A working page with just one URL being bogus with a warning for the dev >>> the whole application crashing.
t/http-router-named-urls.t
Outdated
| } | ||
|
|
||
| { | ||
| my $*CRO-ROOT-URL = 'https://foobar.com'; |
There was a problem hiding this comment.
Hm, I think we should probably do this by looking at the Host header of the HTTP request...though maybe a fallback is useful too.
There was a problem hiding this comment.
No idea, I was piggybacking the test written by @vendethiel here.
The logic should probably be dynamic var // host header value?
t/http-router-named-urls.t
Outdated
|
|
||
| test-route-urls route :name<main>, { | ||
| get :name<home>, -> { | ||
| is make-link('main.home'), '/', 'Basic call of a generator by a short name is correct'; |
There was a problem hiding this comment.
Think I'd call this a qualified name, not a short name.
t/http-router-named-urls.t
Outdated
| } | ||
| }, X::Cro::HTTP::Router::DuplicateLinkName, message => "Conflicting link name: main.home"; | ||
|
|
||
| # XXX the test intention is bogus? |
There was a problem hiding this comment.
Arguably yes; at the very least, if we do build a qualified table, it's a separate thing from the unqualified one.
t/http-router-named-urls.t
Outdated
|
|
||
| test-route-urls route { | ||
| get -> { | ||
| say make-link('hello', 'world'); |
0d2da6a to
13e7019
Compare
Resolve issues we had due to information loss at handlers being flattened after inclusion, make tests pass again as the conflict detection is more strict and at the same time smart now.
Here we do three things: * Before that, URLs constructed for a route had no idea they can be used in some outer route block, so they generated `/foo` instead of `/included-prefix/foo`. To overcome this, we add an url-prefix attribute when we include a handler we rewrite it to an appropriate value. * Before that, we suffered at referencing the correct names due to route flattening. Inner anonymous routes had their handlers not present in the outermost hash, and given the hash was implemented as an attribute on the route set, they were in fact unable to refer to proper names. To overcome this, instaed of using an attribute we rely on the plugin system which allows us to separately store the data of inner route blocks. * This commit also adapts tests to accommodate to removal of the urls attribute available before. There is now a fallback method, though it's possible it will be removed as well in next commits due to its redundancy.
13e7019 to
dca1047
Compare
|
Doing some testing. Some findings: |
|
If I change the above example to: Then all of the examples stop working, complaining that they want the qualified name, however qualification should be optional. |
|
Also expanded with some non-working ones for included routes: |
| next if $param ~~ Cro::HTTP::Router::Header; | ||
| next if $param ~~ Cro::HTTP::Router::Cookie; |
There was a problem hiding this comment.
Ooh, right, we should do also the same if it's Cro::HTTP::Router::Auth too.
There was a problem hiding this comment.
Ah, and if the parameter type does Cro::HTTP::Auth also.
… ago to current code (Altai-man++)
… ago to current code (Altai-man++)
Copy diff from `Support link generation #152` from 4 years ago to current code (Altai-man++)
|
Closing this older version of the PR, since #208 is now merged. |
No description provided.