|
NAMEHTML::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)]
);
DESCRIPTIONthis 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
METHODS
EXAMPLESKEEP SESSION IDtypical 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 PAGINGtemplate 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)]
);
AUTHORIKEBE Tomohiro <ikebe@livedoor.jp> SEE ALSOHTML::Parser HTML::FillInForm CREDITSFixes,Bug Reports. Tatsuhiko Miyagawa <miyagawa@bulknews.net> COPYRIGHTCopyright(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.
|