Next: Introduction, Previous: (dir), Up: (dir) [Contents][Index]
This is the clavier Reference Manual, generated automatically by Declt version 4.0 beta 2 "William Riker" on Mon Aug 15 04:11:45 2022 GMT+0.
Next: Systems, Previous: The clavier Reference Manual, Up: The clavier Reference Manual [Contents][Index]
Clavier is a general purpose validation library for Common Lisp.
Through Quicklisp:
(ql:quickload :clavier)
Validators are class instances that validate the arguments passed to the validate
function:
(let ((validator (make-instance 'equal-to-validator :object 22)))
(validate validator 22 :error-p t))
;=> T
If the validator succeeds, the validate function returns T
. If it fails, the validate function either signals a validation error, or returns NIL
and a validation message depending on the value of the :error-p
argument.
(let ((validator (make-instance 'equal-to-validator :object 22)))
(validate validator 33 :error-p nil))
;=>
;NIL
;"33 is not equal to 22"
Validators are implemented as funcallable classes. So, alternatively to using the validate
function, it is possible to just funcall the validator, like this:
(let ((validator (make-instance 'equal-to-validator :object 22)))
(funcall validator 22 :error-p t))
;=> T
It is possible to create validators with a more convenient syntax. Each validator provides a builder function. For instance, and equal-to-validator can be built like this:
(funcall (== 100) 100) ;=> T
(funcall (== 100) 99) ;=> NIL
This allows to compose validators, using ==
, ~=
, &&
, ||
as the composition operands:
(let ((validator (|| (&& (greater-than 20)
(less-than 30))
(|| (&& (greater-than 1)
(less-than 10))
(== 100)))))
(funcall validator 5))
Validators messages to be used when validation fails can be customized passing an :message
argument when building the validator
Validation errors can controlled globally by setting the dynamic variable *signal-validation-errors*
, which is NIL
by default (no validation errors are signaled by default).
There's also the with-signal-validation-errors
macro to specify whether validation errors should be signaled or not in a dynamic extent. For instance, this code signals a validation error:
(let ((validator (make-instance 'equal-to-validator :object 22)))
(with-signal-validation-errors (t)
(validate validator 33)))
Use the collecting-validation-errors
macro to collect validation errors happening in a dynamic extent:
(let ((validator (make-instance 'equal-to-validator :object 22)))
(collecting-validation-errors (errors found-p)
(progn
(funcall validator 33 :error-p t)
(funcall validator 44 :error-p t))
(print errors)
(print found-p)))
;=>
;(#<VALIDATION-ERROR 44: 44 is not equal to 22 {1008A48673}>
; #<VALIDATION-ERROR 33: 33 is not equal to 22 {1008A47EA3}>)
;T
Next: Files, Previous: Introduction, Up: The clavier Reference Manual [Contents][Index]
The main system appears first, followed by any subsystem dependency.
Clavier: A Common Lisp validation library
Mariano Montone
MIT
Clavier
———-
[](http://quickdocs.org/clavier/)
[](./LICENSE)
*Clavier* is a general purpose validation library for Common Lisp.
Install
——-
Through Quicklisp:
“‘lisp
(ql:quickload :clavier)
“‘
Getting started
—————
Validators are class instances that validate the arguments passed to the ‘validate‘ function:
“‘lisp
(let ((validator (make-instance ’equal-to-validator :object 22)))
(validate validator 22 :error-p t))
;=> T
“‘
If the validator succeeds, the validate function returns ‘T‘. If it fails, the validate function either signals a validation error, or returns ‘NIL‘ and a validation message depending on the value of the ‘:error-p‘ argument.
“‘lisp
(let ((validator (make-instance ’equal-to-validator :object 22)))
(validate validator 33 :error-p nil))
;=>
;NIL
;"33 is not equal to 22"
“‘
Validators are implemented as funcallable classes. So, alternatively to using the ‘validate‘ function, it is possible to just funcall the validator, like this:
“‘lisp
(let ((validator (make-instance ’equal-to-validator :object 22)))
(funcall validator 22 :error-p t))
;=> T
“‘
## Validation expressions
It is possible to create validators with a more convenient syntax. Each validator provides a builder function. For instance, and equal-to-validator can be built like this:
“‘lisp
(funcall (== 100) 100) ;=> T
(funcall (== 100) 99) ;=> NIL
“‘
## Validators composition
This allows to compose validators, using ‘==‘, ‘~=‘, ‘&&‘, ‘||‘ as the composition operands:
“‘lisp
(let ((validator (|| (&& (greater-than 20)
(less-than 30))
(|| (&& (greater-than 1)
(less-than 10))
(== 100)))))
(funcall validator 5))
“‘
## Validators messages
Validators messages to be used when validation fails can be customized passing an ‘:message‘ argument when building the validator
## Catching and collecting validation errors
Validation errors can controlled globally by setting the dynamic variable ‘*signal-validation-errors*‘, which is ‘NIL‘ by default (no validation errors are signaled by default).
There’s also the ‘with-signal-validation-errors‘ macro to specify whether validation errors should be signaled or not in a dynamic extent. For instance, this code signals a validation error:
“‘lisp
(let ((validator (make-instance ’equal-to-validator :object 22)))
(with-signal-validation-errors (t)
(validate validator 33)))
“‘
Use the ‘collecting-validation-errors‘ macro to collect validation errors happening in a dynamic extent:
“‘lisp
(let ((validator (make-instance ’equal-to-validator :object 22)))
(collecting-validation-errors (errors found-p)
(progn
(funcall validator 33 :error-p t)
(funcall validator 44 :error-p t))
(print errors)
(print found-p)))
;=>
;(#<VALIDATION-ERROR 44: 44 is not equal to 22 {1008A48673}>
; #<VALIDATION-ERROR 33: 33 is not equal to 22 {1008A47EA3}>)
;T
“‘
## Validators list:
* equal-to-validator
* not-equal-to-validator
* blank-validator
* not-blank-validator
* true-validator
* false-validator
* type-validator
* string-validator
* boolean-validator
* integer-validator
* symbol-validator
* keyword-validator
* function-validator
* email-validator
* regex-validator
* url-validator
* not-validator
* and-validator
* or-validator
* one-of-validator
* less-than-validator
* greater-than-validator
* length-validator
Next: Packages, Previous: Systems, Up: The clavier Reference Manual [Contents][Index]
Files are sorted by type and then listed depth-first from the systems components trees.
Next: clavier/package.lisp, Previous: Lisp, Up: Lisp [Contents][Index]
clavier (system).
Next: clavier/clavier.lisp, Previous: clavier/clavier.asd, Up: Lisp [Contents][Index]
clavier (system).
Previous: clavier/package.lisp, Up: Lisp [Contents][Index]
package.lisp (file).
clavier (system).
Next: Definitions, Previous: Files, Up: The clavier Reference Manual [Contents][Index]
Packages are listed by definition order.
common-lisp.
Next: Indexes, Previous: Packages, Up: The clavier Reference Manual [Contents][Index]
Definitions are sorted by export status, category, package, and then by lexicographic order.
Next: Internals, Previous: Definitions, Up: Definitions [Contents][Index]
Next: Macros, Previous: Public Interface, Up: Public Interface [Contents][Index]
Next: Ordinary functions, Previous: Special variables, Up: Public Interface [Contents][Index]
Enables/disables validation errors in body
Args: - signal(boolean) : If **T**, errors are signaled. If **NIL**, they are not.
Next: Generic functions, Previous: Macros, Up: Public Interface [Contents][Index]
Returns the validator message for the given object
Next: Standalone methods, Previous: Ordinary functions, Up: Public Interface [Contents][Index]
automatically generated reader method
automatically generated writer method
Next: Conditions, Previous: Generic functions, Up: Public Interface [Contents][Index]
Next: Classes, Previous: Standalone methods, Up: Public Interface [Contents][Index]
error.
(quote (error "set up the target"))
:target
This slot is read-only.
(quote (error "provide the error message"))
:error-msg
This slot is read-only.
Previous: Conditions, Up: Public Interface [Contents][Index]
Initarg | Value |
---|---|
:message | (lambda (validator object) (format nil ~a or ~a (let ((x-validator (x validator))) (validator-message x-validator object)) (let ((y-validator (y validator))) (validator-message y-validator object)))) |
Initarg | Value |
---|---|
:message | (lambda (validator object) (declare (ignorable validator object)) (format nil should be blank)) |
Initarg | Value |
---|---|
:type | (quote boolean) |
:message | (lambda (validator object) (format nil ~a is not a boolean object)) |
Initarg | Value |
---|---|
:message | (lambda (validator object) (declare (ignorable validator object)) (format nil ~a is not a valid timestamp object)) |
Initarg | Value |
---|---|
:message | (lambda (validator object) (declare (ignorable validator object)) (format nil the email is invalid: ~a object)) |
Initarg | Value |
---|---|
:message | (lambda (validator object) (format nil ~a is not equal to ~a object (object validator))) |
(error "provide the object")
:object
Initarg | Value |
---|---|
:message | (lambda (validator object) (declare (ignorable validator object)) (format nil is not false)) |
common-lisp.
(error "provide the function")
:function
Initarg | Value |
---|---|
:message | (lambda (validator object) (declare (ignorable validator object)) (format nil ~a is not greater than ~a object (validator-number validator))) |
common-lisp.
(error "provide the number")
:number
Initarg | Value |
---|---|
:type | (quote integer) |
:message | (lambda (validator object) (format nil ~a is not an integer object)) |
Initarg | Value |
---|---|
:type | (quote keyword) |
:message | (lambda (validator object) (format nil ~a is not a keyword object)) |
Initarg | Value |
---|---|
:message | size is not correct |
Minimum length
common-lisp.
:min
Maximum length
common-lisp.
:max
Message for when length is below minimum
:min-message
Message for when length is above maximum
:max-message
Initarg | Value |
---|---|
:message | (lambda (validator object) (declare (ignorable validator object)) (format nil ~a is not lower than ~a object (validator-number validator))) |
common-lisp.
(error "provide the number")
:number
Initarg | Value |
---|---|
:type | (quote list) |
:message | (lambda (validator object) (format nil ~a is not a list object)) |
Initarg | Value |
---|---|
:message | (lambda (validator object) (declare (ignorable validator object)) (format nil should not be blank)) |
Initarg | Value |
---|---|
:message | (lambda (validator object) (format nil ~a is equal to ~a object (object validator))) |
(error "provide the object")
:object
Initarg | Value |
---|---|
:message | (lambda (validator object) (format nil not ~a (validator-message (validator validator) object))) |
(error "provide the validator")
:validator
Initarg | Value |
---|---|
:message | (lambda (validator object) (declare (ignorable validator object)) (format nil should be one of ~{~a~} (options validator))) |
(error "provide the options")
:options
Initarg | Value |
---|---|
:message | (lambda (validator object) (format nil ~a and ~a (let ((x-validator (x validator))) (validator-message x-validator object)) (let ((y-validator (y validator))) (validator-message y-validator object)))) |
Initarg | Value |
---|---|
:message | (lambda (validator object) (declare (ignorable validator object)) (format nil ~a is not a valid pathname object)) |
If the pathname should be absolute
:absolute-p
Probe existance of pathname
:probe-p
The pathname type
common-lisp.
:pathname-type
Initarg | Value |
---|---|
:message | (lambda (validator object) (declare (ignorable validator object)) (format nil ~a does not match the regex ~s object (validator-regex validator))) |
(error "provide the regex")
:regex
Initarg | Value |
---|---|
:type | (quote string) |
:message | (lambda (validator object) (declare (ignore validator)) (format nil ~s is not a string object)) |
Initarg | Value |
---|---|
:type | (quote symbol) |
:message | (lambda (validator object) (format nil ~a is not a symbol object)) |
Initarg | Value |
---|---|
:message | (lambda (validator object) (declare (ignorable validator object)) (format nil is not true)) |
Initarg | Value |
---|---|
:message | (lambda (validator object) (format nil ~a is not of type ~a object (validator-type validator))) |
common-lisp.
(error "provide the type")
:type
Initarg | Value |
---|---|
:message | (lambda (validator object) (declare (ignorable validator object)) (format nil ~a is not a valid url object)) |
funcallable-standard-object.
(error "provide the validation error message")
:message
Initarg | Value |
---|---|
:message | (lambda (&rest args) ) |
:validators
Previous: Public Interface, Up: Definitions [Contents][Index]
Next: Generic functions, Previous: Internals, Up: Internals [Contents][Index]
Previous: Ordinary functions, Up: Internals [Contents][Index]
If the pathname should be absolute
automatically generated reader method
automatically generated reader method
automatically generated writer method
automatically generated writer method
automatically generated reader method
automatically generated writer method
The pathname type
Probe existance of pathname
automatically generated reader method
automatically generated writer method
Maximum length
max.
Message for when length is above maximum
Minimum length
min.
Message for when length is below minimum
automatically generated reader method
automatically generated reader method
automatically generated writer method
automatically generated writer method
automatically generated reader method
automatically generated writer method
automatically generated reader method
type.
automatically generated writer method
type.
automatically generated reader method
automatically generated writer method
automatically generated reader method
x.
automatically generated reader method
x.
automatically generated writer method
x.
automatically generated writer method
x.
automatically generated reader method
y.
automatically generated reader method
y.
automatically generated writer method
y.
automatically generated writer method
y.
Previous: Definitions, Up: The clavier Reference Manual [Contents][Index]
Jump to: | %
&
(
=
~
∅
A B C F G I L M N O P V W X Y |
---|
Jump to: | %
&
(
=
~
∅
A B C F G I L M N O P V W X Y |
---|
Next: Data types, Previous: Functions, Up: Indexes [Contents][Index]
Jump to: | *
A E F M N O P R S T V X Y |
---|
Jump to: | *
A E F M N O P R S T V X Y |
---|
Jump to: | A B C D E F G I K L N O P R S T U V |
---|
Jump to: | A B C D E F G I K L N O P R S T U V |
---|