RejectedSoftware Forums

Sign up

Some tests using UDAs

Hi. I got time to play a bit with UDAs and vibe, and while this isn't much, I think the possibilities for more declarative code looks good.

module myapp;
mixin CurrentModule;

@(page.get("/")) void index(HTTPServerRequest req, HTTPServerResponse res) {
    res.renderCompat!"index.dt"();
}

shared static this() {
    auto router = new URLRouter();
    router.addRoutesFromMembersOf!__CurrentModule;
}

Notice @(page.get"/") and addRoutesFromMembersOf!__CurrentModule.

Next up is trying to fix UDAs for the inject pattern. Hopefully I can write the following

@(page.get("/"))
@(requires!(userLoggedIn, hasRights!(addUser)))
void add_user(Params...)( // etc

Is anyone else playing around with UDAs and vibe?

Re: Some tests using UDAs

On Sat, 14 Sep 2013 13:58:55 GMT, simendsjo wrote:

Hi. I got time to play a bit with UDAs and vibe, and while this isn't much, I think the possibilities for more declarative code looks good.

module myapp;
mixin CurrentModule;

@(page.get("/")) void index(HTTPServerRequest req, HTTPServerResponse res) {
    res.renderCompat!"index.dt"();
}

shared static this() {
    auto router = new URLRouter();
    router.addRoutesFromMembersOf!__CurrentModule;
}

Notice @(page.get"/") and addRoutesFromMembersOf!__CurrentModule.

Next up is trying to fix UDAs for the inject pattern. Hopefully I can write the following

@(page.get("/"))
@(requires!(userLoggedIn, hasRights!(addUser)))
void add_user(Params...)( // etc

Is anyone else playing around with UDAs and vibe?

Oops.. the @page should be @route

Re: Some tests using UDAs

Am 14.09.2013 15:58, schrieb simendsjo:

Hi. I got time to play a bit with UDAs and vibe, and while this isn't much, I think the possibilities for more declarative code looks good.

 module myapp;
 mixin CurrentModule;

 @(page.get("/")) void index(HTTPServerRequest req, HTTPServerResponse res) {
     res.renderCompat!"index.dt"();
 }

 shared static this() {
     auto router = new URLRouter();
     router.addRoutesFromMembersOf!__CurrentModule;
 }

Notice @(page.get"/") and addRoutesFromMembersOf!__CurrentModule.

Next up is trying to fix UDAs for the inject pattern. Hopefully I can write the following

 @(page.get("/"))
 @(requires!(userLoggedIn, hasRights!(addUser)))
 void add_user(Params...)( // etc

Is anyone else playing around with UDAs and vibe?

The vibe.http.form module is supposed to be extended in that direction
(basically it shall get the same UDA support that vibe.http.rest
already has). Once this is finished, it would mean that the use case you
outlined is possible + support for automatic form to parameter
conversion. The interface also needs to be extended a bit for non-member
functions and a few other things, too.

Re: Some tests using UDAs

On Sat, 14 Sep 2013 18:47:39 +0200, Sönke Ludwig wrote:

The vibe.http.form module is supposed to be extended in that direction
(basically it shall get the same UDA support that vibe.http.rest
already has). Once this is finished, it would mean that the use case you
outlined is possible + support for automatic form to parameter
conversion. The interface also needs to be extended a bit for non-member
functions and a few other things, too.

It is actually quite an interesting option to move those UDA's to router module itself and make generic.

So that this overload will be added:

router.add!handler(default_method, default_url)

Wich will check handler symbol for http method and url UDA's and register matching route. It can then be used as generic interface in all modules, including the OP proposal.

Re: Some tests using UDAs

Am 16.09.2013 15:13, schrieb Dicebot:

On Sat, 14 Sep 2013 18:47:39 +0200, Sönke Ludwig wrote:

The vibe.http.form module is supposed to be extended in that direction
(basically it shall get the same UDA support that vibe.http.rest
already has). Once this is finished, it would mean that the use case you
outlined is possible + support for automatic form to parameter
conversion. The interface also needs to be extended a bit for non-member
functions and a few other things, too.

It is actually quite an interesting option to move those UDA's to router module itself and make generic.

So that this overload will be added:

router.add!handler(default_method, default_url)

Wich will check handler symbol for http method and url UDA's and register matching route. It can then be used as generic interface in all modules, including the OP proposal.

Good idea, it should be orthogonal to all the parameter/JSON/form
handling. I would rather implement it as a UFCS function, though, to
keep URLRouter itself simple.