12.07.2015 Views

Slides - Common Lisp.net

Slides - Common Lisp.net

Slides - Common Lisp.net

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Un<strong>Common</strong> Webor: How I Learned to Stop Worrying and Love theWeb


• Marco Baringer • http://common-lisp.<strong>net</strong>/project/ucw


The Problem• The tools don’t allow us to, directly, saywhat we think.


It’s HTTP’s fault• HTTP, which is an asynchronous andstateless protocol, considers every request/response as an independant object.• Developers consider every request andresponse as a part of a sequence ofinteractions.


What do we want to say?An application is not a set ofdistinct pages as much as aset of sequences of pages.Example: First we show theshopping cart page, then, ifthe user wants, they cancontinue to the payment infopage, finally they can viewthe confirm order page.CartPaymentConfirm


So What?• When developers think about an applicationthey think in terms of what happens beforeand after a particular page.• Every page in the application represents apoint within a well defined sequence andhas a past and a future.


Continuations• Continuations are a tool to work with the“future.”• They allow us to express, directly, what willhapppen after a user has seen a page.


Continuations - Part II• They’re functions• They’re created with “magic” operators.• They can be called more than once.• They contain, other than the code, the stateof the world at the time they were created.


Example(defaction purchase (cart)(show “order-contents”)(show “payment”)(show “confirm”))


UCWthe Un<strong>Common</strong> Web application framework


Continuations in UCW• Simulated by transforming the originalsource code.• Not a perfect solution (doesn’t handle everyconstruct in the original language) but it’smore than enough for our needs.


Components• The state, the behaviour and the graphics ofevery GUI element (window, menu, form,navigation bar, …) are represented by acomponent.• Every component, just like a normalfunction, is called and returns a value.


Actions• Every user action (following a link,submitting a form) calls an action.• An action can pass control to anothercomponent (call), or return control (answer).• When a component passes control toanother component it is replaced by theother camponent.


BacktrackingDealing with users who go back and take a different road.• When a page is generated the state of theapplication is saved.• Before handling an action the state of theapplication is restored to what is was.


Rendering• Every component must, if it’s visible on thescreen, be able to transform itself intoHTML.• UCW provides two tools for generatingHTML: yaclml e tal.


YACLMLLibrary of lisp macros which allow html to beembedded into the code:(


TALTemplating library which puts code inside theHTML:…


Exampleexamples/counter.lisp


The RERL Protocol• The handling of every request/response pairis specified in terms of classes and genericfunctions.• UCW is simply one possible implementationof this protocol.


class component• continuation - what to do when thiscomponent finishes.• calling-component - who created thiscomponent.• render-on - method which generates theHTML for this component.


class request-contextall the information regarding an http request/responsepair• application• session• request• response• current-frame• window-component


generic function servicethe methods which do all the work• Handles an object (an application, a sessionor a session-frame) within a request-context.


class session-framea single interaction with the server• method call-callback - call the handlerassociated with an http request parameter.• window-component - the “root”component. this component must create theHTML for the entire browser window (butwill rarely do this without the help of othercomponents)


class sessiona set of interactions by the same user with the sameapplication• method get-value - returns the value in thesession associated with a particular key.


class applicationset of entry-points and sessions.• url-prefix - the url space this applicationcontrols.• method make-request-context - create a newrequest-context object.• method find-session - given a requestcontextreturns (or creates) the sessionobject.


class serverA UCW instance• applications - the set of applications livingin the server.• backend - The object which deals withHTTP.• method handle-request - deal with a pair ofhttp request and response objects.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!