Liking cljdoc? Tell your friends :D

shuriken.monkey-patch

### Tools to monkey-patch Clojure and Java code
raw docstring

define-againclj

(define-again namespaced-sym)

Refreshes a var by evaluating its source. Preserves metadata.

Refreshes a var by evaluating its source. Preserves metadata.
sourceraw docstring

java-patchcljmacro

(java-patch & args)

Applies a monkey-patch to a java method.

mode can be either :replace, :before or :after. body can be javassist pseudo-java (a string) or clojure code. In the latter case, args must be specified before body so as to intercept the method's parameters. If :after is used args will include the method's return value. If the method is an instance method, args will also include the instance it is called on (this).

args: [this? return-value? & method-args]

(java-patch [clojure.lang.LispReader "read"
             [java.io.PushbackReader "boolean" Object "boolean" Object]]
  :replace
  [reader eof-is-error eof-value _is-recursive opts]
  (clojure.tools.reader/read
    (merge {:eofthrow eof-is-error
            :eof eof-value}
           opts)
    reader))

;; or

(java-patch [clojure.lang.LispReader$SyntaxQuoteReader "syntaxQuote"
             [Object]]
  :after
  "{
     $_ = clojure.lang.RT.list(
       clojure.lang.Symbol.intern("clojure.core", "from-syntax-quote"),
       $_
     );
  }")
Applies a monkey-patch to a java method.

`mode` can be either `:replace`, `:before` or `:after`.
`body` can be javassist pseudo-java (a string) or clojure code.
In the latter case, `args` must be specified before `body` so as to
intercept the method's parameters. If `:after` is used `args` will
include the method's return value. If the method is an instance
method, `args` will also include the instance it is called on
(`this`).

`args`: `[this? return-value? & method-args]`

```clojure
(java-patch [clojure.lang.LispReader "read"
             [java.io.PushbackReader "boolean" Object "boolean" Object]]
  :replace
  [reader eof-is-error eof-value _is-recursive opts]
  (clojure.tools.reader/read
    (merge {:eofthrow eof-is-error
            :eof eof-value}
           opts)
    reader))

;; or

(java-patch [clojure.lang.LispReader$SyntaxQuoteReader "syntaxQuote"
             [Object]]
  :after
  "{
     $_ = clojure.lang.RT.list(
       clojure.lang.Symbol.intern("clojure.core", "from-syntax-quote"),
       $_
     );
  }")
```
sourceraw docstring

monkey-patchcljmacro

(monkey-patch name target args & body)
(monkey-patch perfid-incer clojure.core/+ [original & args]
  (inc (apply original args)))

(+ 1 2)
=> 4

Supports reload. Name and target can be vars or symbols. Name can also be a keyword.

```clojure
(monkey-patch perfid-incer clojure.core/+ [original & args]
  (inc (apply original args)))

(+ 1 2)
=> 4
```

Supports reload. Name and target can be vars or symbols. Name can also be
a keyword.
sourceraw docstring

onlycljmacro

(only name & body)

Ensures body is executed only once with respect to name. If name is a symbol or a keyword without a namespace, it will be prefixed with the value of *ns*.

(only 'foo (println "bar"))
; prints bar

(only 'foo (println "bar"))
; prints nothing
Ensures `body` is executed only once with respect to `name`.
If `name` is a symbol or a keyword without a namespace, it will be
prefixed with the value of `*ns*`.

```clojure
(only 'foo (println "bar"))
; prints bar

(only 'foo (println "bar"))
; prints nothing
```
sourceraw docstring

primitive-typesclj

source

refresh-onlyclj

(refresh-only name)

Reset only statements by name. Next time one is called, the associated code will be evaluated. If name is a symbol or a keyword without a namespace, it will be prefixed with *ns*.

(only 'foo (println "bar"))
; prints bar

(refresh-only 'foo)
(only 'foo (println "bar"))
; prints bar
Reset `only` statements by name. Next time one is called, the
associated code will be evaluated.
If `name` is a symbol or a keyword without a namespace, it will be
prefixed with `*ns*`.

```clojure
(only 'foo (println "bar"))
; prints bar

(refresh-only 'foo)
(only 'foo (println "bar"))
; prints bar
```
sourceraw docstring

require-from-dependent-namespacesclj

(require-from-dependent-namespaces requirement)

Requires a namespace from any namespace that has required it. requirement can be anything require accepts.

(require-from-dependent-namespaces
  '[clojure.core :refer [custom-fn]])
Requires a namespace from any namespace that has required it.
`requirement` can be anything `require` accepts.

```clojure
(require-from-dependent-namespaces
  '[clojure.core :refer [custom-fn]])
```
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close