1#!../../src/xotclsh
2# $Id: Counter3.xotcl,v 1.1 2004/05/23 22:50:39 neumann Exp $
3array set opts {-pkgdir .}; array set opts $argv
4lappend auto_path $opts(-pkgdir)
5
6package require XOTcl 1; namespace import -force xotcl::*
7package require xotcl::actiweb::htmlPlace
8package require xotcl::actiweb::webDocument
9
10### Instantiate an Html place with the name receiver
11HtmlPlace ::receiver -port 8093  -allowExit exit
12
13### Define a class solely for counting
14Class Counter -parameter {{count 1}}
15Counter instproc increment {} {    ;### counter method
16  my incr count
17}
18
19### Define a special WebCounter as a specialization of the Counter class 
20Class WebCounter -superclass {Counter HtmlDocument}
21WebCounter instproc init args {    ;### Constructor
22  next
23  my persistent count              ;### make count variable persistent
24  ::receiver exportObjs [self]     ;### export the counter object
25  my exportProcs increment         ;### export increment method
26}
27WebCounter instproc default {} {  ;### Method for updating HTML page
28  set objName [string trimleft [self] :]
29  return "<HTML>The value in $objName is [my set count].<p>
30	<A HREF='[my selfAction increment]'>Increment Counter</a><p>
31	<HR>Last Update: [clock format [clock seconds] -format %m/%d/%y-%H:%M]
32	</HTML>\n"
33}
34WebCounter instproc increment {} { ;### exported increment method
35  next                             ;### call superclasses' increment
36  my default                      ;### display the result as HTML
37}
38
39### Create two web counter instances with the names c1 and c2
40WebCounter c1
41WebCounter c2
42
43### Start event loop and handle connections
44receiver startEventLoop 
45