RejectedSoftware Forums

Sign up

@before with member function

What is a good approach to associate @before function with this of a REST interface?

int someBeforeFunction(HTTPServerRequest req, HTTPServerResponse res)
{
    // I want my REST implementation here!
    return 0;
}

interface MyInterface
{
    @before!someBeforeFunction("some"):
    void myFunction(int some);
}

Currently the only approach i see is referencing through an explicit static variable. Is there a better solution?

Re: @before with member function

On Thu, 03 Jul 2014 13:30:05 GMT, Yuriy wrote:

What is a good approach to associate @before function with this of a REST interface?

int someBeforeFunction(HTTPServerRequest req, HTTPServerResponse res)
{
    // I want my REST implementation here!
    return 0;
}

interface MyInterface
{
    @before!someBeforeFunction("some"):
    void myFunction(int some);
}

Currently the only approach i see is referencing through an explicit static variable. Is there a better solution?

I've recently written a little (hygienic) mixin based hack to support member functions and private functions for @before/@after for registerWebInterface(). This isn't yet ported to registerRestInterface(), though:

class MyWebService {
	private {
		int m_someInt;
	}

	// defined in vibe.internal.meta.funcattr
	mixin PrivateAccessProxy;

	@before!someBeforeFunction("_someint")
	void getSomething(int _someint)
	{
	}

	private int someBeforeFunction(HTTPServerRequest req, HTTPServerResponse res)
	{
		return m_someInt;
	}
}

I've opened #708 for this.

Re: @before with member function

That's great, although looks hacky. Can't wait to see it working for REST.

Re: @before with member function

On Thu, 03 Jul 2014 15:09:03 GMT, Yuriy wrote:

That's great, although looks hacky. Can't wait to see it working for REST.

I think the right solution would rather be to change how D handles protection attributes w.r.t alias template parameters. Currently the protection is checked when the alias is accessed, but it would arguable make a lot or more sense instead to do that check where the template is instantiated.

Then there would only be a second issue (I think), and that is that there seems to be no way to directly invoke a member function alias on a specific this instance other than calling it from within another member function of that instance.

So currently using a proxy method is really the only way to make this work AFAIK.