[hunchentoot-devel] resurrect tbnl's debug-value macro?

Mac Chan emailmac at gmail.com
Thu May 3 08:14:54 UTC 2007


I just noticed today that one of the tbnl's best features is missing
in hunchentoot.

Previously (in tbnl) if you set *debug-mode* to T, the top level
dynamic vars *request*, *reply*, etc will be bound to the last
request, reply objects.

This is very handy and in line with Lisp's interactive development model.

I usually setup an empty handler and point the browser to that URL.

Now I can work with the *request* / *reply* objects in the REPL, and
write html generation and GET/POST handling code interactively.

For instance, I can type these in the REPL

> (setf hunchentoot::*session* (hunchentoot::session-verify *request*))

> (session-value :selected-product)
"T-Shirt XXL"

> (* (product-price *) (session-value :quantity))
15

and so on.

Once I'm satisfied with the result, I put all the code into the handler.

(defun product-total-page (&optional (request *request*))
  (let ((p (session-value :selected-product))
        (q (session-value :quantity)))
   (with-html
     (:html
      (:body
       (:table
        (:tr (:td "Product") (:td (str p)))
        (:tr (:td "Quantity") (:td (str q)))
        (:tr (:td "Total") (:td (str (* q (product-price p)))))))))))

This is also very handy for debugging (inspect *request*'s slots -
cookies, header and whatnot).

Thoughts?

-- Mac



More information about the Tbnl-devel mailing list