/src/core/component.lisp

http://github.com/fukamachi/clack · Lisp · 70 lines · 48 code · 15 blank · 7 comment · 3 complexity · 3f2dfbfc584fa59f0e0b3812dc070dea MD5 · raw file

  1. #|
  2. This file is a part of Clack package.
  3. URL: http://github.com/fukamachi/clack
  4. Copyright (c) 2011 Eitarow Fukamachi <e.arrows@gmail.com>
  5. Clack is freely distributable under the LLGPL License.
  6. |#
  7. (clack.util:namespace clack.component
  8. (:use :cl))
  9. (cl-syntax:use-syntax :annot)
  10. @export
  11. (deftype component-designator ()
  12. "A designator for a `<component>` which can be `clack.component:call`able."
  13. '(or function
  14. <component>))
  15. @export
  16. (defclass <component> () ()
  17. (:documentation
  18. "Base Class for Clack Component shared between <middleware> and Clack Application."))
  19. @export
  20. (defgeneric call (comp env)
  21. (:documentation "Invoke component. Designed to be overriden in subclasses."))
  22. @export
  23. (defmethod call ((app function) env)
  24. "Functions should be called like Component."
  25. (funcall app env))
  26. @export
  27. (defmethod make-app ((comp <component>))
  28. "Create a function to call this component."
  29. #'(lambda (env) (call comp env)))
  30. (doc:start)
  31. @doc:NAME "
  32. Clack.Component - Base Class for Clack Component.
  33. "
  34. @doc:SYNOPSIS "
  35. (in-package :cl-user)
  36. (defpackage clack.app.example
  37. (:use :cl :clack)
  38. (:export :<clack-app-example>))
  39. (in-package :clack.app.example)
  40. (defclass <clack-app-example> (<component>) ())
  41. (defmethod call ((this <clack-app-example>) env)
  42. (declare (ignore this env))
  43. `(200 (:content-type \"text/plain\") (\"Hello, World!\")))
  44. "
  45. @doc:DESCRIPTION "
  46. Clack.Component is the base class shared between Clack.Middleware and Clack Application.
  47. You must implement `clack.component:call' as a method which is called when an HTTP request comes in and returns a response.
  48. "
  49. @doc:AUTHOR "
  50. * Eitarow Fukamachi (e.arrows@gmail.com)
  51. "
  52. @doc:SEE "
  53. * Clack.Middleware
  54. "