Skip to content

Instantly share code, notes, and snippets.

@robertpfeiffer
Created January 25, 2009 12:06
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 robertpfeiffer/51768 to your computer and use it in GitHub Desktop.
Save robertpfeiffer/51768 to your computer and use it in GitHub Desktop.
(defn before-advice [fun]
(fn [original]
(fn [& args] (apply original (apply fun args)))))
(defn after-advice [fun]
(partial comp fun))
(defn around-advice [fun]
(fn [original]
(fun original)))
(defn weave [pointcut namespaces & advice]
(let [advice (apply comp (reverse advice))]
(doseq [join-point (filter pointcut (vals (mapcat ns-interns namespaces)))]
(prn join-point (meta join-point))
(alter-var-root join-point advice))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment