1#!../../src/xotclsh 2# $Id: Counter.xotcl,v 1.4 2006/09/27 08:12:39 neumann Exp $ 3#load /Users/neumann/src/xotcl-1.4.1/library/store/XOTclSdbm/libxotclsdbm1.2.dylib 4array set opts {-pkgdir .}; array set opts $argv 5lappend auto_path $opts(-pkgdir) 6 7package require XOTcl 1; namespace import -force xotcl::* 8package require xotcl::actiweb::htmlPlace 9package require xotcl::actiweb::webDocument 10 11### Instantiate an Html place with the name receive and port 8090 12HtmlPlace ::receiver -port 8090 -allowExit exit 13 14### Define a class Counter as a special Html Document 15Class Counter -superclass HtmlDocument -parameter {{count 0}} 16 17Counter instproc init args { ;### Constructor 18 next 19 my persistent count ;### make count variable persistent 20 ::receiver exportObjs [self] ;### export the counter object 21 my exportProcs increment ;### export counter's increment method 22} 23Counter instproc default {} { ;### Method for updating HTML page 24 set objName [string trimleft [self] :] 25 return "<HTML>The value in $objName is now: [my set count].<p> 26 <A HREF='$objName+increment'>Increment Counter</a><p> 27 <HR>Last Update: [clock format [clock seconds]] 28 </HTML>\n" 29} 30Counter instproc increment {} { ;### exported increment method 31 my incr count 32 return [my default] 33} 34 35### Create two counter instances with the names 36### counter-1.html and counter-2.html 37Counter counter-1.html 38Counter counter-2.html 39 40### Start event loop and handle connections 41receiver startEventLoop 42 43