Friday, August 6, 2010

Tcl and AOL

Tcl is a programming system developed by John Ousterhout at the University of California, Berkeley. According to Dr. Ousterhout:

Tcl is a simple scripting language for controlling and extending applications; its name stands for "tool command language". Tcl provides generic programming facilities, such as variables and loops and procedures, that are useful in a variety of applications. Furthermore, Tcl is embedable. Its interpreter is a library of C procedures that can easily be incorporated into applications, and each application can extend the core Tcl features with additional commands for that application.
AOLserver supports the Tcl v7.6 commands. When you write AOLserver extensions in Tcl, you use the core functionality of Tcl as well as a set of AOLserver-specific Tcl functions. For example, there is an AOLserver Tcl function called ns_conn that allows your Tcl script to obtain information about the current connection. In addition, functions are available for returning results to Web clients, accessing databases, and managing the permissions (access control) system.

This book describes the two different methods for extending AOLserver with Tcl, using AOLserver Dynamic Pages (Chapter 2) and Tcl libraries (see Chapter 3), plus general information on using Tcl with either method (see Chapter 4). It also provides a reference for AOLserver's Tcl API (see Chapter 5).

Recommended Reading

For more information on the Tcl language, we recommend the following sources:

* Practical Programming in Tcl and Tk, by Brent B. Welch (Prentice Hall PTR, 1995)

* Tcl and the Tk Toolkit, by John K. Ousterhout (Addison-Wesley, 1994)

* For the complete manual pages for the Tcl v7.6 commands, visit the web site http://www.scriptics.com/man.

* Philip Greenspun's web site, http://www-swiss.ai.mit.edu/wtr/dead-trees/, which includes chapters from his book, Database Backed Web Sites, The Thinking Person's Guide to Web Publishing, and numerous examples of AOLserver Tcl database applications.

* The web site: http://www.yahoo.com/Computers_and_Internet/Programming_Languages/ Tcl_Tk


Why Use Tcl?
You can extend AOLserver using Tcl, C, or CGI. However, using Tcl has the following advantages:

* Creating new Tcl scripts is very easy. You can embed Tcl scripts directly into HTML pages using AOLserver Dynamic Pages (ADPs), or you can create .tcl files and register them to handle URLs or URL hierarchies.

* Tcl's scripting language is easier to learn and use than compiled programming languages. It provides general programming capabilities, such as variables, loops, and procedures, but it doesn't require strong type definitions or compilation. Plus, AOLserver's Tcl interface provides a complete set of Tcl extensions specifically oriented towards web server applications, such as returning content to the client, accessing form data, accessing databases, and logging.

* Many of the basic AOLserver services are implemented as Tcl scripts. In fact, most of the database operations such as handling database inserts, queries, and updates, are written as Tcl scripts. Not only has the Tcl interface greatly reduced the development time for the AOLserver engineering team, it also allows you to easily modify the basic database operations by simply editing the Tcl scripts that implement the functionality.

* The Tcl and C interfaces typically provide better performance than CGI. However, if you have existing CGI programs, you may want to use AOLserver's CGI interfaces to take advantage of previously-existing code.

The C interface for AOLserver is described in the AOLserver C Developer's Guide, and the CGI interface is desribed in the AOLserver Administrator's Guide.


ADPs and Tcl Libraries
There are two ways to extend AOLserver using Tcl, and each is better-suited to different situations:

* AOLserver Dynamic Pages (ADPs): ADPs allow you to embed Tcl scripts directly into HTML pages. The script(s) are interpreted dynamically when the page is accessed. ADPs are ideal in situations where you want to generate all or part of a specific page dynamically. You can re-use code by storing Tcl scripts in Tcl libraries and invoking them from within multiple ADPs. You can also include files and parse other ADPs from within your ADPs.

* Tcl Libraries: The alternative to embedding Tcl scripts in HTML pages using ADPs, is to store Tcl scripts in Tcl libraries. You can define scripts that can be called from ADPs, schedule procedures to run at certain times, register scripts to handle specific URLs or URL hierarchies, register scripts to handle all URLs with a specific file extension, and register filters to be run in addition to a URL's registered procedure.

No comments: