From c29b8eeed4000ef25ed387d06121ec192222f753 Mon Sep 17 00:00:00 2001 From: Maciej Pasternacki Date: Tue, 25 Nov 2008 14:46:45 +0100 Subject: [PATCH] - Handler functions. --- doc/TRANE-COMMON.html | 17 ++++++++++++++++- doc/generate-docs.lisp | 3 ++- src/common.lisp | 26 ++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/doc/TRANE-COMMON.html b/doc/TRANE-COMMON.html index 15f26d0..92ad8bd 100644 --- a/doc/TRANE-COMMON.html +++ b/doc/TRANE-COMMON.html @@ -17,6 +17,11 @@ Defaults to "error" in *DEFAULT-PATHNAME-DEFAULTS*.
Initial value: #P"state/error"
+

*handler-package*   variable

+
Package, in which HANDLER-FUNCTION looks for handlers. + +When NIL, *PACKAGE* is assumed, which is probably not what you want.
+
Initial value: NIL

(cache-dao dao)   function

Manually add DAO to cache used by WITH-DAO-CACHE.

DIRTINESS-MIXIN

   undocumented

DIRTY-P

   undocumented

@@ -25,7 +30,17 @@ Defaults to "error" in *DEFAULT-PATHNAME-DEFAULTS*. STATEMENTS may be either S-SQL expressions, literal SQL strings, or lists of statements.

FORMAT-ERROR-REPORT

   undocumented

-

(id object)   generic-function

+

(handler-function &rest name-parts)   function

+
Return handler function whose name consists of NAME-PARTS. + +Handler function name is NAME-PARTS joined with slash signes, and +starting with a slash; NIL part means an empty place. E.g. for +NAME-PARTS :FOO :BAR :BAZ, it's /FOO/BAR/BAZ; for :FOO NIL it's /FOO/; +and for NIL :XYZZY it's //XYZZY. + +If symbol with such name exists in *HANDLER-PACKAGE* (or in *PACKAGE*, +if *HANDLER-PACKAGE* is NIL, but probably it's not what you want), and +it names a function, this function is returned.

(id object)   generic-function

Numeric ID or :NULL for DAOs and, if it makes sense, other objects. Usually it will be a reader method automatically defined for ID column of a DAO.

(init-config &rest files)   function

diff --git a/doc/generate-docs.lisp b/doc/generate-docs.lisp index a9ee47a..4a3ea66 100644 --- a/doc/generate-docs.lisp +++ b/doc/generate-docs.lisp @@ -9,7 +9,8 @@ (trane-dependency-graph:graph (merge-pathnames "dependency-graph.dot" *dir*)) (let ((trane-common:*config* (py-configparser:make-config)) - (trane-common:*db* nil)) + (trane-common:*db* nil) + (trane-common:*handler-package* nil)) (lispdoc:lispdoc-html *dir* :trane-common :trane-bb :trane-taxonomy :trane-passengers)) #+b0rken (tinaa:document-system ':asdf-system :cl-trane (merge-pathnames "html/" *dir*)) diff --git a/src/common.lisp b/src/common.lisp index 4e09b3f..c642f74 100644 --- a/src/common.lisp +++ b/src/common.lisp @@ -15,6 +15,7 @@ #:report-error #:report-error-by-email #:report-error-to-file #:format-error-report #:*error-context-hook* #:*error-report-pathname-defaults* #:make-keyword #:named-lambda #:random-string #:salted-password + #:*handler-package* #:handler-function #:start-hunchentoot)) (in-package #:trane-common) @@ -328,3 +329,28 @@ implementations." "Return Base64-encoded MD5 checksum of SALT concatenated with PASSWORD." (cl-base64:usb8-array-to-base64-string (md5:md5sum-sequence (concatenate 'string salt password)))) + +(defvar *handler-package* nil + "Package, in which HANDLER-FUNCTION looks for handlers. + +When NIL, *PACKAGE* is assumed, which is probably not what you want.") + +(defun handler-function (&rest name-parts) + "Return handler function whose name consists of NAME-PARTS. + +Handler function name is NAME-PARTS joined with slash signes, and +starting with a slash; NIL part means an empty place. E.g. for +NAME-PARTS :FOO :BAR :BAZ, it's /FOO/BAR/BAZ; for :FOO NIL it's /FOO/; +and for NIL :XYZZY it's //XYZZY. + +If symbol with such name exists in *HANDLER-PACKAGE* (or in *PACKAGE*, +if *HANDLER-PACKAGE* is NIL, but probably it's not what you want), and +it names a function, this function is returned." + (multiple-value-bind (sym type) + (find-symbol (format nil "~{/~@[~A~]~}" name-parts) + (or *handler-package* *package*)) + (when (and (not (eql type :inherited)) + (fboundp sym)) + (let ((fn (symbol-function sym))) + (when (functionp fn) + fn))))) -- 2.11.4.GIT