books
Free Books / Computers / Practical mod_perl /

previous page: E.3.1. Handling Form Parameters
  
page up: Practical mod_perl | by Stas Bekman and Eric Cholet
  
next page: E.3.3. Sending Email

E.3.2. Handling Cookies




Description

This section is from the "Practical mod_perl" book, by Stas Bekman and Eric Cholet. Also available from Amazon: Practical mod_perl

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

Books by Stas Bekman:















TOP
previous page: E.3.1. Handling Form Parameters
  
page up: Practical mod_perl | by Stas Bekman and Eric Cholet
  
next page: E.3.3. Sending Email

Topics

  • Animals
  • Architecture
  • Arts
  • Business
  • Computers
  • Crafts
  • Fairy Tales
  • Finance
  • Flora and Plants
  • Cooking
  • Gardening
  • Health and Healing
  • History
  • Home Improvements
  • Languages
  • New Age
  • Novels
  • Real Estate
  • Reference
  • Religion
  • Science
  • Society
  • Sports
  • Travel
  • Outdoors


Search

My Books

Headaches Begone! A Systemic Approach To Healing Your Headaches
Don't Let Your Bike Seat Ruin Your Sex Life Book

Discover

  • Answers FAQ

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

© 2007-2021 StasoSphere.com