HTML::StickyQuery(3)

NAME
HTML::StickyQuery - add sticky QUERY_STRING

SYNOPSIS
  use HTML::StickyQuery;

  # create an object
  my $s = HTML::StickyQuery->new(
       regexp => '\.cgi$',
       abs => 0,
       keep_original => 1,
  );

  print $s->sticky(
      file => 'foo.html',
      param => { SESSIONID => 'xxx' }
  );

 or

  my $q = CGI->new;
  print $s->sticky(
      file => 'foo.html',
      param => $q,
      sticky_keys => [qw(SESSIONID)]
  );

DESCRIPTION
this module is a sub class of HTML::Parser. parse HTML document and add QUERY_STRING to href attributes. Handy for maintaining state without cookie or something, transparently.

if you want to use sticky CGI data via FORM. it is better to use HTML::FillInForm.

CONSTRUCTOR

new(%option)
    constructor of HTML::StickyQuery object. the options are below.

    abs add QUERY_STRING to absolute URI or not. (default: 0)

    override
        this option is obsolete. please use keep_original option.

    keep_original
        keep original QUERY_STRING or not. (default: 1) when this option is false. all old QUERY_STRING is removed.

    regexp
        regular expression of affected URI. (default: none)

METHODS

sticky(%options)
    parse HTML and add QUERY_STRING. return HTML document. the options are below.

    file
        specify the HTML file.

    scalarref
        specify the HTML document as scalarref.

    arrayref
        specify the HTML document as arrayref.

    param
        QUERY_STRING data. as hashref or object which implements param method. (eg. CGI, Apache::Request)

    sticky_keys
        specify sticky data keys as arrayref. any keys which are not in this list are ignored. if not specified, all keys are kept.

EXAMPLES

  KEEP SESSION ID
typical example of CGI application using session.

use Apache::Session,HTML::Template and HTML::StickyQuery

template file:

 <html>
 <head>
 <title>Session Test</title>
 </head>
 <body>
 COUNT: <TMPL_VAR NAME="count"><br>
 <hr>
 <a href="session.cgi">countup</a><br>
 <hr>
 </body>
 </html>

session.cgi:

 #!perl

 use strict;
 use CGI;
 use HTML::Template;
 use HTML::StickyQuery;
 use Apache::Session::DB_File;

 my %session;
 my $cgi = CGI->new;

 # create session.
 my $id = $cgi->param('SESSIONID');
 tie %session,'Apache::Session::DB_File',$id,{
                                              FileName => './session.db',
                                              LockDirectory => './lock'
 };

 $session{count} = $session{count} + 1;

 my $tmpl = HTML::Template->new(filename => './test.html');

 $tmpl->param(count => $session{count});

 my $output = $tmpl->output;

 # no COOKIE
 print $cgi->header;

 my $stq = HTML::StickyQuery->new;
 print $stq->sticky(
     scalarref => \$output,
     param => { SESSIONID => $session{_session_id} }
 );

  KEEP SEARCH WORD IN HTML PAGING
template file (simplified):

  <A href="./search.cgi?pagenum=<TMPL_VAR name=nextpage>">Next 20 results</A>

search.cgi:

  #!perl
  use CGI;
  use HTML::StickyQuery;
  use HTML::Template;

  my $query = CGI->new;
  my $tmpl  = HTML::Template->new(filename => 'search.html');

  # do searching with $query and put results into $tmpl
  # ...

  # set next page offset
  $tmpl->param(nextpagee => $query->param('pagenum') + 1);

  my $output = $tmpl->output;
  my $sticky = HTML::StickyQuery->new(regexp => qr/search\.cgi$/);
  print $query->header, $sticky->sticky(
      scalarref => \$output,
      param => $qyery,
      sticky_keys => [qw(search)]
  );

AUTHOR
IKEBE Tomohiro <ikebe@livedoor.jp>

SEE ALSO
HTML::Parser HTML::FillInForm

CREDITS
Fixes,Bug Reports.

Tatsuhiko Miyagawa <miyagawa@bulknews.net>

COPYRIGHT
Copyright(C) 2002 IKEBE Tomohiro All rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.