AxKit::XSP::Cookie is a taglib interface to Apache::Cookie (part of the libapreq package). The following example demonstrates both retrieving and setting a cookie from within XSP. In order for this to run, the following option needs to be added to your httpd.conf file:
AxAddXSPTaglib AxKit::XSP::Cookie
The XSP page is shown in Example E-4.
<xsp:page xmlns:xsp="http://apache.org/xsp/core/v1" xmlns:cookie="http://attic.apache.org/projects/axkit.html/NS/xsp/cookie/v1" language="Perl" > <page> <xsp:logic> my $value; if ($value = <cookie:fetch name="count"/>) { $value++; } else { $value = 1; } </xsp:logic> <cookie:create name="count"> <cookie:value><xsp:expr>$value</xsp:expr></cookie:value> </cookie:create> <p>Cookie value: <xsp:expr>$value</xsp:expr></p> </page> </xsp:page>
This page introduces the concept of XSP expressions, using the <xsp:expr> tag. In XSP, everything that returns a value is an expression of some sort. In the last two examples, we have used a taglib tag within a Perl if( )statement. These tags are both expressions, even though they don't use the <xsp:expr>syntax. In XSP, everything understands its context and tries to do the right thing. The following three examples will all work as expected:
<cookie:value>3</cookie:value> <cookie:value><xsp:expr>2 + 1</xsp:expr></cookie:value> <cookie:value><param:cookie_value/></cookie:value>
We see this as an extension of how Perl works—the idea of "Do What I Mean," or DWIM.
 
Continue to: