File: processing.xml

package info (click to toggle)
libapache2-mod-rivet 3.2.6-1
  • links: PTS
  • area: main
  • in suites: sid, trixie
  • size: 6,384 kB
  • sloc: tcl: 8,982; xml: 8,619; ansic: 7,074; sh: 5,039; makefile: 195; sql: 91; lisp: 78
file content (116 lines) | stat: -rw-r--r-- 5,125 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<section id="processing">
	<title>Apache Rivet HTTP Request Processing</title>
	<section>
		<title>Tcl Scripts Processing</title>
		<para>
			Until &version2-generic; versions Rivet handled requests
			following the vision that inspired the original design
			which was summarized in the definition <quote>Web programming
			like in PHP, but with Tcl</quote>. HTTP requests triggered the
			execution of Tcl scripts or a Rivet (.rvt file) templates
			whose path is encoded in the URI (an alias translation or
			URL rewriting might occur to establish the real path). 
			The execution of such scripts can be preceded and/or 
			followed by the execution of scripts common to a whole web site
			or to a hierarchy of directories the BeforeScript and AfterScript
			directives. These scripts can be configured on a per virtual host, 
			per directory or per user basis. Execution of such combined
			scripts can break because of coding errors (thus triggering the
			ErrorScript execution) or it can deliberately interrupt 
			ordinary execution by calling ::rivet::abort_page (which triggers
			the execution of a script defined by the directive AbortScript). 
			This scheme is in case terminated by a further configurable script 
			(AfterEveryScript). This model of request handling was coded within
			the module mod_rivet.so itself. 
		</para>
		<para>
 			With Rivet &version30; we changed this approach and landed to
 			a new much simpler and flexible model where each request is 
 			by default handled by the following Tcl procedure
		</para>

		<programlisting>&request_handler.tcl;</programlisting>

		<para>
			Note the call to new &version3-generic; command ::rivet::url_script
			that returns the body of the Tcl script or Rivet template
			pointed by the URL. 
		</para>
		
		<para>
			This procedure emulates the &version2-generic; scheme
			and as such works as a fully compatible request handling
			but opens to the programmers the option of replacing it 
			with their own	application request handling procedure
		</para>
		
		<note>
			Note that if you redefine the core request handler
			you'll need to handle yourself any error conditions
			and any code interruption brought about by calling 
			<command>::rivet::abort_page</command>.
			The current procedure might work as a template to be
			reworked into your own request handler.
		</note>
	</section>
	
	<section>
		<title>Example: basic OO Rivet Application</title>
		<para>
			An applications may have no interest in running
			a script pointed by the URL as in the traditional approach 
			followed by rivet inspired to the PHP philosophy of <quote>scripting
			the HTML</quote>. A web based application
			could be driven entirely by the URL encoded arguments and by the
			data POSTed with HTML forms, still retaining the ability of exploiting
			the template engine of Rivet through the <command>::rivet::parse</command>.
			In other words an application could hinge on a single entry point to
			handle requests, regardless the complexity of its internal design. 
		</para>
		<para>This section shows a template for such an application 
			(let's call it MyRivetApp) based on an Itcl (or TclOO for what 
			it matters) object instance. In myrivetapp.tcl
			the application class is defined and an instance of it is
			created in the global namespace. 
		</para>
		<programlisting>&myrivetapp.tcl;</programlisting>
		<para>
			which provides a very basic interface for both initialization
			and request processing. Such script will be sourced into the
			Tcl interpreter at the mod_rivet initialization stage. In the
			Apache configuration (most
			likely within a &lt;VirtualHost myrivetapp.com:80&gt;...&lt;/VirtualHost&gt;
			definition block)
		</para>
		<programlisting>&lt;IfModule rivet_module&gt;
    RivetServerConf ChildInitScript "source myrivetapp.tcl"
&lt;/IfModule&gt;</programlisting>
		<para>
			By running this script when an a thread is started
			we set it up to respond requests, but we still need to 
			tell mod_rivet what code will eventually handle requests
			and how the method MyRivetApp::request_processing will
			be called with appropriate arguments
		</para>
		<programlisting>&myapp_request_handler.tcl;</programlisting>
	</section>
	<para>
		Finally we have to tell mod_rivet to run this script when a
		request is delivered to myApplication and we do so
		using the &version30; directive <command>RequestHandler</command> 
	</para>
	<programlisting>&lt;IfModule rivet_module&gt;
    RivetServerConf ChildInitScript "source myrivetapp.tcl"
    RivetServerConf RequestHandler  "myapp_request_handler.tcl"
&lt;/IfModule&gt;</programlisting>
	<para>
		Notice that the argument of the directive <command>RequestHandler</command>
		is a file name not a Tcl script as for <command>ChildInitScript</command>
	</para>
	<para>
		With such approach only the <command>ChildInitScript</command>, <command>ChildExitScript</command>
		and <command>GlobalInitScript</command> configuration directives are effective, while 
		the effect of other handler is devolved to our request handler script.
	</para>

</section>