pax_global_header00006660000000000000000000000064114761460150014517gustar00rootroot0000000000000052 comment=157c52b6a24397974305cc9244b977cef17741cf perl-HTML-StickyQuery-0.13/000075500000000000000000000000001147614601500154365ustar00rootroot00000000000000perl-HTML-StickyQuery-0.13/.gitignore000064400000000000000000000001521147614601500174240ustar00rootroot00000000000000cover_db META.yml Makefile blib inc pm_to_blib MANIFEST Makefile.old nytprof.out *.sw[po] *~ *.bak test.plperl-HTML-StickyQuery-0.13/.shipit000064400000000000000000000001411147614601500167330ustar00rootroot00000000000000steps = FindVersion, ChangeVersion, CheckChangeLog, DistTest, Commit, Tag, MakeDist, UploadCPAN perl-HTML-StickyQuery-0.13/Changes000064400000000000000000000030211147614601500167250ustar00rootroot000000000000000.13 2010-12-03 IKEBE Tomohiro * use parent. * modern layout. 2003-10-08 IKEBE Tomohiro * added valid XML(XHTML) support. (Thanks to Kensaku Fujiwara) 2003-05-29 IKEBE Tomohiro * support boolean attributes. (Thanks to Tatsuhiko Miyagawa * 0.09 * now accept paramable objects. (Thanks to Hiroyuki Kobayasi ) * fixed docs. * 0.10 * added sticky_keys option * rewrite all test codes by Test::More 2002-05-01 IKEBE Tomohiro * 0.08 * keep comment and declaration. 2002-01-21 IKEBE Tomohiro * 0.07 * default behavior, keep_original => 1. * think about backward compat. 2002-01-18 IKEBE Tomohiro * 0.06 * [API change] override option was obsolete. instead, keep_original option is available. (Thanks to Tatsuhiko Miyagawa ) 2001-10-19 IKEBE Tomohiro * 0.05 * fixed escape HTML problem. * save order of attributes. 2001-10-18 IKEBE Tomohiro * 0.04 * fixed override, when original URI has QUERY_STRING which has same key (Thanks to Tatsuhiko Miyagawa ) * fixed URI scheme handling problem. * add arrayref parse. 2001-10-17 IKEBE Tomohiro * 0.03 * use Test::Harness. * add regexp support. 2001-10-17 IKEBE Tomohiro * 0.02 * add test code. perl-HTML-StickyQuery-0.13/MANIFEST.SKIP000064400000000000000000000003071147614601500173340ustar00rootroot00000000000000\bRCS\b \bCVS\b ^MANIFEST\. ^Makefile$ ~$ ^# \.old$ ^blib/ ^pm_to_blib ^MakeMaker-\d \.gz$ \.cvsignore ^t/9\d_.*\.t ^t/perlcritic ^tools/ \.svn/ ^[^/]+\.yaml$ ^[^/]+\.pl$ ^\.shipit$ ^\.git \.sw[po]$ perl-HTML-StickyQuery-0.13/Makefile.PL000064400000000000000000000004331147614601500174100ustar00rootroot00000000000000use inc::Module::Install; name 'HTML-StickyQuery'; all_from 'lib/HTML/StickyQuery.pm'; # requires ''; tests 't/*.t'; author_tests 'xt'; requires 'parent'; requires 'HTML::Parser' => '3.00'; requires 'URI'; test_requires 'Test::More'; auto_set_repository; auto_include; WriteAll; perl-HTML-StickyQuery-0.13/README000064400000000000000000000103641147614601500163220ustar00rootroot00000000000000NAME 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 the HTML::Parser manpage. 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 the HTML::FillInForm manpage. 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 the Apache::Session>,L Session Test COUNT:

countup

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): Next 20 results 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 SEE ALSO the HTML::Parser manpage the HTML::FillInForm manpage CREDITS Fixes,Bug Reports. Tatsuhiko Miyagawa 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. perl-HTML-StickyQuery-0.13/lib/000075500000000000000000000000001147614601500162045ustar00rootroot00000000000000perl-HTML-StickyQuery-0.13/lib/HTML/000075500000000000000000000000001147614601500167505ustar00rootroot00000000000000perl-HTML-StickyQuery-0.13/lib/HTML/StickyQuery.pm000064400000000000000000000172161147614601500216110ustar00rootroot00000000000000package HTML::StickyQuery; # $Id: StickyQuery.pm,v 1.10 2003/10/08 09:46:55 ikebe Exp $ use strict; use parent qw(HTML::Parser); use URI; use vars qw($VERSION); $VERSION = '0.13'; sub new { my $class = shift; _croak("odd number of " . __PACKAGE__ . "->new arguments") if @_ % 2; my %args = @_; my $self = bless { keep_original => 1, abs => 0, regexp => undef, }, $class; foreach my $key(qw(keep_original abs regexp)) { $self->{$key} = $args{$key} if exists $args{$key}; } # backward compat $self->{keep_original} = !$args{override} if $args{override}; $self->SUPER::init; $self->boolean_attribute_value('__BOOLEAN__'); $self; } sub sticky { my $self = shift; my %args = @_; if (ref $args{param} eq 'HASH') { $self->{param} = $args{param} } elsif ($args{param}->can("param")) { my %data = (); for my $key($args{param}->param) { my @val = $args{param}->param($key); $data{$key} = scalar(@val) > 1 ? \@val : $val[0]; } $self->{param} = \%data; } if ($args{sticky_keys}) { my %sticky = map { $_ => 1 } @{$args{sticky_keys}}; my %new; while (my($k, $v) = each %{$self->{param}}) { $new{$k} = $v if $sticky{$k} } $self->{param} = \%new; } $self->{output} = ""; if ($args{file}) { $self->parse_file($args{file}); } elsif ($args{scalarref}) { $self->parse(${$args{scalarref}}); } elsif ($args{arrayref}) { foreach my $line(@{$args{arrayref}}) { $self->parse($line); } } return $self->{output}; } sub output { my $self = shift; return $self->{output}; } sub start { my ($self, $tagname, $attr, $attrseq, $orig) = @_; if ($tagname ne 'a') { $self->{output} .= $orig; return; } else { unless(exists $attr->{href}) { $self->{output} .= $orig; return; } my $u = URI->new($attr->{href}); # skip absolute URI if (!$self->{abs} && $u->scheme) { $self->{output} .= $orig; return; } # when URI has other scheme (ie. mailto ftp ..) if(defined($u->scheme) && $u->scheme !~ m/^https?/) { $self->{output} .= $orig; return; } else { if (!$self->{regexp} || $u->path =~ m/$self->{regexp}/) { if ($self->{keep_original}) { my %original; my @original = $u->query_form; while (my ($key, $val) = splice(@original, 0, 2)) { if (exists $original{$key}) { if (ref $original{$key} eq 'ARRAY') { push @{$original{$key}}, $val; } else { $original{$key} = [ $original{$key}, $val ]; } } else { $original{$key} = $val; } } my %merged = (%original, %{$self->{param}}); $u->query_form(%merged); } else { $u->query_form(%{$self->{param}}); } $self->{output} .= qq{<$tagname}; # save attr order. foreach my $key(@$attrseq) { if ($key eq "href"){ $self->{output} .= sprintf(qq{ href="%s"}, $self->escapeHTML($u->as_string)); } elsif ($attr->{$key} eq '__BOOLEAN__') { $self->{output} .= " $key"; } else { $self->{output} .= sprintf(qq{ $key="%s"}, $self->escapeHTML($attr->{$key})); } } $self->{output} .= '>'; return; } $self->{output} .= $orig; } } } sub process { my($self, $text, $orig) = @_; $self->{output} .= $orig; } sub end { my ($self, $tagname, $orig) = @_; $self->{output} .= $orig; } sub text { my ($self, $orig) = @_; $self->{output} .= $orig; } sub comment { my ($self, $orig) = @_; $self->{output} .= qq//; } sub declaration { my ($self, $orig) = @_; $self->{output} .= qq//; } sub _croak { require Carp; Carp::croak(@_); } sub escapeHTML { my $self = shift; my $text = shift; $text =~ s/&/&/g; $text =~ s/"/"/g; $text =~ s//>/g; return $text; } 1; __END__ =head1 NAME HTML::StickyQuery - add sticky QUERY_STRING =head1 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)] ); =head1 DESCRIPTION this module is a sub class of L. 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 L. =head1 CONSTRUCTOR =over 4 =item new(%option) constructor of HTML::StickyQuery object. the options are below. =over 5 =item abs add QUERY_STRING to absolute URI or not. (default: 0) =item override this option is obsolete. please use keep_original option. =item keep_original keep original QUERY_STRING or not. (default: 1) when this option is false. all old QUERY_STRING is removed. =item regexp regular expression of affected URI. (default: I) =back =back =head1 METHODS =over 4 =item sticky(%options) parse HTML and add QUERY_STRING. return HTML document. the options are below. =over 5 =item file specify the HTML file. =item scalarref specify the HTML document as scalarref. =item arrayref specify the HTML document as arrayref. =item param QUERY_STRING data. as hashref or object which implements I method. (eg. CGI, Apache::Request) =item 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. =back =back =head1 EXAMPLES =head2 KEEP SESSION ID typical example of CGI application using session. use L,L and L template file: Session Test COUNT:

countup

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} } ); =head2 KEEP SEARCH WORD IN HTML PAGING template file (simplified): Next 20 results 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)] ); =head1 AUTHOR IKEBE Tomohiro Eikebe@livedoor.jpE =head1 SEE ALSO L L =head1 CREDITS Fixes,Bug Reports. Tatsuhiko Miyagawa Emiyagawa@bulknews.netE =head1 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. =cut perl-HTML-StickyQuery-0.13/t/000075500000000000000000000000001147614601500157015ustar00rootroot00000000000000perl-HTML-StickyQuery-0.13/t/01load.t000064400000000000000000000001051147614601500171420ustar00rootroot00000000000000 use Test::More tests => 1; BEGIN { use_ok("HTML::StickyQuery"); } perl-HTML-StickyQuery-0.13/t/02file.t000064400000000000000000000003361147614601500171510ustar00rootroot00000000000000 use Test::More tests => 1; use HTML::StickyQuery; # file my $s = HTML::StickyQuery->new; $s->sticky( file => './t/test.html', param => {SID => 'xxx'} ); like($s->output,qr##); perl-HTML-StickyQuery-0.13/t/03scalarref.t000064400000000000000000000004621147614601500201750ustar00rootroot00000000000000 use Test::More tests => 1; use HTML::StickyQuery; # scalarref open(FILE,"./t/test.html") or die $!; my $data = join('',); close(FILE); my $s = HTML::StickyQuery->new; $s->sticky( scalarref => \$data, param => {SID => 'xxx'} ); like($s->output, qr##); perl-HTML-StickyQuery-0.13/t/04keep_original.t000064400000000000000000000007471147614601500210520ustar00rootroot00000000000000use Test::More tests => 3; use HTML::StickyQuery; { my $s = HTML::StickyQuery->new; $s->sticky( file => './t/test2.html', param => { SID => 'xyz', foo => 'baz' } ); like($s->output, qr/SID=xyz/); like($s->output, qr/foo=baz/); } { my $s = HTML::StickyQuery->new(keep_original => 0); $s->sticky( file => './t/test2.html', param => {SID => 'xyz'} ); like($s->output, qr##); } perl-HTML-StickyQuery-0.13/t/05regexp.t000064400000000000000000000004501147614601500175240ustar00rootroot00000000000000 use Test::More tests => 1; use HTML::StickyQuery; my $s = HTML::StickyQuery->new( regexp => '^/cgi-bin/' ); $s->sticky( file => './t/test3.html', param => {SID => 'xxx'} ); is($s->output, ''); perl-HTML-StickyQuery-0.13/t/06abs.t000064400000000000000000000007451147614601500170070ustar00rootroot00000000000000 use Test::More tests => 2; use HTML::StickyQuery; my $s = HTML::StickyQuery->new; $s->sticky( file => './t/test4.html', param => {SID => 'xxx'} ); is($s->output,''); my $s2 = HTML::StickyQuery->new( abs => 1 ); $s2->sticky( file => './t/test4.html', param => {SID => 'xxx'} ); is($s2->output, ''); perl-HTML-StickyQuery-0.13/t/07arrayref.t000064400000000000000000000004421147614601500200500ustar00rootroot00000000000000 use Test::More tests => 1; use HTML::StickyQuery; # arrayref open(FILE,"./t/test.html") or die $!; my @data = ; close(FILE); my $s = HTML::StickyQuery->new; $s->sticky( arrayref => \@data, param => {SID => 'xxx'} ); like($s->output, qr##); perl-HTML-StickyQuery-0.13/t/08escape.t000064400000000000000000000003561147614601500175020ustar00rootroot00000000000000 use Test::More tests => 1; use HTML::StickyQuery; my $s = HTML::StickyQuery->new; $s->sticky( file => 't/test5.html', param => {SID => 'xxx'} ); like($s->output, qr##); perl-HTML-StickyQuery-0.13/t/09comment.t000064400000000000000000000003431147614601500177010ustar00rootroot00000000000000 use Test::More tests => 2; use HTML::StickyQuery; my $s = HTML::StickyQuery->new; $s->sticky( file => 't/test6.html', param => {a => 'xxx'} ); like($s->output, qr/output, qr//); perl-HTML-StickyQuery-0.13/t/10multiple.t000064400000000000000000000003551147614601500200650ustar00rootroot00000000000000 use Test::More tests => 2; use HTML::StickyQuery; # file my $s = HTML::StickyQuery->new; $s->sticky( file => './t/test.html', param => { SID => ['xxx', 'yyy'] } ); like($s->output, qr/SID=xxx/); like($s->output, qr/SID=yyy/); perl-HTML-StickyQuery-0.13/t/11param.t000064400000000000000000000004751147614601500173360ustar00rootroot00000000000000 use Test::More; use HTML::StickyQuery; use CGI; BEGIN{plan tests => 3} my $s = HTML::StickyQuery->new; my $q = CGI->new({ foo => ['bar', 'baz'], bar => 'baz'}); $s->sticky( file => './t/test.html', param => $q ); like($s->output, qr/foo=bar/); like($s->output, qr/foo=baz/); like($s->output, qr/bar=baz/); perl-HTML-StickyQuery-0.13/t/12sticky_keys.t000064400000000000000000000006021147614601500205700ustar00rootroot00000000000000 use Test::More tests => 4; use HTML::StickyQuery; use CGI; my $s = HTML::StickyQuery->new; my $q = CGI->new({ foo => ['bar', 'baz'], bar => 'baz', aaa => 'bbb'}); $s->sticky( file => './t/test.html', param => $q, sticky_keys => [qw(foo aaa)] ); like($s->output, qr/foo=bar/); like($s->output, qr/foo=baz/); like($s->output, qr/aaa=bbb/); unlike($s->output, qr/bar=baz/); perl-HTML-StickyQuery-0.13/t/13standalongtag.t000064400000000000000000000003251147614601500210600ustar00rootroot00000000000000 use Test::More tests => 1; use HTML::StickyQuery; use CGI; my $s = HTML::StickyQuery->new; my $q = CGI->new(); $s->sticky( file => './t/standalone.html', param => $q, ); unlike($s->output, qr/z="z"/); perl-HTML-StickyQuery-0.13/t/14xhtml.t000064400000000000000000000005111147614601500173640ustar00rootroot00000000000000 use Test::More tests => 2; use HTML::StickyQuery; use CGI; my $s = HTML::StickyQuery->new; my $q = CGI->new(); $s->sticky( file => './t/xhtml.html', param => $q, ); like($s->output, qr/<\?xml version="1.0" encoding="utf-8"\?>/); like($s->output, qr( foo perl-HTML-StickyQuery-0.13/t/test.html000064400000000000000000000000261147614601500175440ustar00rootroot00000000000000perl-HTML-StickyQuery-0.13/t/test2.html000064400000000000000000000000351147614601500176260ustar00rootroot00000000000000perl-HTML-StickyQuery-0.13/t/test3.html000064400000000000000000000000711147614601500176270ustar00rootroot00000000000000perl-HTML-StickyQuery-0.13/t/test4.html000064400000000000000000000000711147614601500176300ustar00rootroot00000000000000perl-HTML-StickyQuery-0.13/t/test5.html000064400000000000000000000000621147614601500176310ustar00rootroot00000000000000perl-HTML-StickyQuery-0.13/t/test6.html000064400000000000000000000001651147614601500176360ustar00rootroot00000000000000 foo perl-HTML-StickyQuery-0.13/t/xhtml.html000064400000000000000000000006211147614601500177220ustar00rootroot00000000000000 XHTML LINK