Practical mod_perl / HTML Book /



previous page: E.3.1. Handling Form Parameters
  
page up: HTML Version of the book
  
next page: E.3.3. Sending Email

E.3.2. Handling Cookies


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.

Example E-4. cookietaglib.xsp

<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:

  • prev: E.3.1. Handling Form Parameters
  • Table of Contents
  • next: E.3.3. Sending Email







TOP
previous page: E.3.1. Handling Form Parameters
  
page up: HTML Version of the book
  
next page: E.3.3. Sending Email


Menu

  • HTML Book
  • PDF Book
  • Download Code
  • Table of Contents
  • Errata
  • mod_perl2 User's Guide
  • Sitemap

Search


Add to Google




Creative Commons License


Written by
Eric Cholet (Logilune) and
Stas Bekman (StasoSphere & Free Books).


[ Privacy Policy | Terms of Use | About Us | Search ]

© 2007 StasoSphere.com