Skip to content

Instantly share code, notes, and snippets.

@KirinDave
Created October 1, 2010 22:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KirinDave/c9e6eb3c117db6eb7dca to your computer and use it in GitHub Desktop.
Save KirinDave/c9e6eb3c117db6eb7dca to your computer and use it in GitHub Desktop.
(defmacro state [& forms]
(let [state-opts (apply hash-map forms)
opts (resolve-states (merge state-standards state-opts))
has-body? (:body opts)]
(if-not has-body?
`(fn [& [ {request# :request
handler# :handler
response# :response :as args#}]]
(let [test# ~(:test opts)
test-result# (test# handler# request#)
result# (or (:result test-result#)
test-result#)
plan# (if result#
~(:yes opts)
~(:no opts))
nresponse# (if (map? test-result#)
(update-response test-result# response#)
response#)
forward-args# {:request request#
:handler handler#
:response nresponse#}]
(println "Intermediate: " test-result# " -> " result#) ; For debugging
(cond
(map? plan#) plan#
(instance? clojure.lang.IFn plan#) (apply plan# (list args#))
(var? plan#) (apply plan# (list forward-args#))
(keyword? plan#) (list result# plan#)
:default plan#)
))
(throw (Exception. "Not ready yet!")))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment