Created
January 25, 2009 12:32
-
-
Save robertpfeiffer/51776 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn y [a b] (* 3 a b)) | |
;weave an aspect to function in current Namespace | |
(weave #(= 'y (:name (meta %))) [*ns*] | |
(before-advice (fn [& args] (print args) args))) | |
(def io-aspect [(around-advice (fn [proceed] | |
(fn [& args] (io! (apply proceed args))))) | |
(after-advice (fn [result] (flush) result))]) | |
(apply weave #(:output (meta %)) [*ns*] io-aspect) | |
(def in-my-layer nil) | |
(deflayer my-layer | |
in-my-layer true | |
;restrict weaving to this layer | |
weave (fn [pointcut namespaces & advice] | |
(proceed pointcut namespaces (fn [fun] (fn [& args] | |
(apply ((if in-my-layer (apply comp advice) identity) fun) args)))))) | |
(defn xyz [& args] 12) | |
(with-layer my-layer | |
(weave #(= 'xyz (:name (meta %))) [*ns*] | |
(before-advice (fn [& args] (print args) args))) | |
(xyz 1 2 3)) | |
(xyz 1 2 3) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment