#!../../src/xotclsh
# $Id: s.Counter3.xotcl 1.7 01/03/23 22:00:32+01:00 neumann@somewhere.wu-wien.ac.at $
package require xotcl::awo::htmlPlace
package require xotcl::awo::webDocument

### Instantiate an Html place with the name receiver
HtmlPlace ::receiver -port 8093  -allowExit exit

### Define a class solely for counting
Class Counter -parameter {{count 1}}
Counter instproc increment {} {    ;### counter method
  ::incr [self]::count
}

### Define a special WebCounter as a specialization of the Counter class 
Class WebCounter -superclass {Counter HtmlDocument}
WebCounter instproc init args {    ;### Constructor
  next
  [self] persistent count          ;### make count variable persistent
  ::receiver exportObjs [self]     ;### export the counter object
  [self] exportProcs increment     ;### export increment method
}
WebCounter instproc default {} {   ;### Method for updating HTML page
  set objName [string trimleft [self] :]
  return "<HTML>The value in $objName is [[self] set count].<p>
	<A HREF='$objName+increment'>Increment Counter</a><p>
	<HR>Last Update: [clock format [clock seconds] -format %m/%d/%y-%H:%M]
	</HTML>\n"
}
WebCounter instproc increment {} {;### exported increment method
  next                            ;### call superclasses' increment
  return [default]                ;### display the result as HTML
}

### Create two web counter instances with the names c1 and c2
WebCounter c1
WebCounter c2

### Start event loop and handle connections
receiver startEventLoop 
