caveman
caveman copied to clipboard
defroute package lookup
Is it possible at all to create an <app>
instance in one package, and defroute
definitions in another? I'd like to split my project up into multiple packages but caveman2.app::*package-app-map*
stores the app object in a different package than what defroute
's expansion looks for.
You could add in your defroute file
file something like this:
(define-symbol-macro *web* your-app-package::*your-app-map*)
I encountered the same problem when trying to separate my route settings.
I noticed that defroute
is calling functions from ningle
package, but I would say defroute
is doing too much - it should not be locked in the current package. It is not a good design IMHO.
Practically speak, the current implementation is very unfriendly to package-per-file programming style: all routes must be defined in one file. IMHO it would be better if we can specify the <app>
instance in defroute
declaration.
Run into the same today and thought I would share my solution in case anyone was still looking for a workaround for this.
To make DEFROUTE work you have to register the current package into CAVEMAN2.APP::*PACKAGE-APP-MAP* and make sure it points to the main <APP> instance (i.e. *WEB* in my case):
(defun register-routes-package (package)
(setf (gethash package caveman2.app::*package-app-map*) *web*))
With this, you then need to remember to call (register-routes-package *package*)
from each package in which you want to define new routes.
It's ugly, I know, otherwise I would not have called it a workaround ;-)