root/Apache-StickyQuery/trunk/lib/Apache/StickyQuery.pm

Revision 301 (checked in by miyagawa, 19 years ago)

0.02

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 package Apache::StickyQuery;
2
3 use strict;
4 use vars qw($VERSION);
5 $VERSION = '0.02';
6
7 use Apache::Constants qw(:common);
8 use Apache::File;
9 use Carp ();
10 use HTML::StickyQuery;
11
12 sub handler ($$) {
13     my($class, $r) = @_;
14
15     my $filtered = uc($r->dir_config('Filter')) eq 'ON';
16     $r = $r->filter_register if $filtered;
17
18     # only for text/html
19     return DECLINED unless ($r->content_type eq 'text/html' && $r->is_main);
20
21     my($fh, $status);
22     if ($filtered) {
23         ($fh, $status) = $r->filter_input;
24         undef $fh unless $status == OK;
25     } else {
26         $fh = Apache::File->new($r->filename);
27     }
28
29     return DECLINED unless $fh;
30
31     $r->send_http_header;
32
33     local $/;                   # slurp
34     my $input = <$fh>;
35
36     my $stickyquery = $class->make_stickyquery($r);
37     my $paramref    = $class->retrieve_param($r);
38
39     $r->print($stickyquery->sticky(
40         scalarref => \$input, param => $paramref,
41     ));
42     return OK;
43 }
44
45 sub make_stickyquery {
46     my($class, $r) = @_;
47     my %opt = map {
48         my $key = 'StickyQuery' . ucfirst($_);
49         my $val = $r->dir_config($key);
50         defined $val ? ($key => $val) : ();
51     } qw(abs regexp override);
52     return HTML::StickyQuery->new(%opt);
53 }
54
55 sub retrieve_param {
56     my($class, $r) = @_;
57     my %in = $r->args;
58     return \%in;
59 }
60
61 1;
62 __END__
63
64 =head1 NAME
65
66 Apache::StickyQuery - rewrites links using sticky query
67
68 =head1 SYNOPSIS
69
70   # in httpd.conf
71   <Location /stickyquery>
72   SetHandler perl-script
73   PerlHandler Apache::StickyQuery
74   </Location>
75
76   # filter aware
77   PerlModule Apache::StickyQuery
78   SetHandler perl-script
79   PerlSetVar Filter On
80   PerlHandler Apache::RegistryFilter Apache::StickyQuery Apache::Compress
81
82 =head1 DESCRIPTION
83
84 Suppose page transactions like this:
85
86        foo.cgi       =>   bar.html       =>   baz.cgi
87      ?sid=0123456                           ?sid=0123456
88
89 It is difficult to keep sid query parameter between two cgis without
90 cookies (or mod_rewrite hacks).
91
92 Apache::StickyQuery is a filter that rewrites all links in HTML file
93 using "sticky query". It would be useful in keeping state (ie. like
94 Session IDs) without using Cookies. See L<HTML::StickyQuery> for
95 details.
96
97 This module is Filter aware, meaning that it can work within
98 Apache::Filter framework without modification.
99
100 =head1 CONFIGURATION
101
102 StickyQuery parameters are automatically retrieved via current query
103 string. Options to change this is one of TODOs. (Hint: inherit from
104 Apache::StickyQuery and override C<retrieve_param>)
105
106 Apache::StickyQuery has the following configuration variables.
107
108   PerlSetVar StickyQueryAbs 0
109   PerlSetVar StickyQueryOverride 1
110   PerlSetVar StickyQueryRegexp ^/cgi-bin/
111
112 each of which corresponds to those of HTML::StickyQuery. See
113 L<HTML::StickyQuery> for details.
114
115 =head1 AUTHOR
116
117 Tatsuhiko Miyagawa <miyagawa@bulknews.net>
118
119 This library is free software; you can redistribute it and/or modify
120 it under the same terms as Perl itself.
121
122 =head1 SEE ALSO
123
124 L<HTML::StickyQuery>, L<Apache::Filter>
125
126 =cut
Note: See TracBrowser for help on using the browser.