caveman icon indicating copy to clipboard operation
caveman copied to clipboard

defroute package lookup

Open mfiano opened this issue 5 years ago • 3 comments

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.

mfiano avatar May 03 '19 22:05 mfiano

You could add in your defroute file file something like this:

(define-symbol-macro *web* your-app-package::*your-app-map*)

knobo avatar May 06 '19 08:05 knobo

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.

sheepduke avatar Nov 12 '19 04:11 sheepduke

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 ;-)

iamFIREcracker avatar May 02 '21 18:05 iamFIREcracker