clojure-liberator/liberator — pull request #121 by sw1nn (2014-04-11 10:27:47+00:00)
Title: Make resource fn a macro to improve debugability.

When you build up a map of routes -> resources it is helpful to have the
resource handler fn named in a way that helps finding the source.

the defresource macro eventually makes a call to liberator.core/resource
which returns an anonymous handler function. If resource is a function
the anonymous function it returns is defined in the liberator.core
namespace which gives all resources a similar name.

However, If we make resource a macro, then the anonymous function is defined in
the callers namespace, this makes tracking down "I'm somehow routing to
the wrong handler" bugs much easier to debug, because the anonymous function
name in stacktraces changes from something like:

#

to

#

One alternative would be to maintain resource as a function for users to call, but change
the defresource macro to generate the anonymous function directly rather
than calling liberator.core/resource.

A second alternative would be to include the resource name in the
anoymous function, but that prevents resources with the same name in
different namespaces.

The approach in this commit seems minimally invasive whilst adding some
debugability.