File Coverage

blib/lib/Apache/CookieToQuery.pm
Criterion Covered Total %
statement 8 10 80.0
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 12 14 85.7


line stmt bran cond sub pod time code
1             package Apache::CookieToQuery;
2 1     1   853 use strict;
  1         2  
  1         54  
3              
4             BEGIN {
5 1     1   6 use vars qw ( $VERSION @COOKIE_NAMES %COOKIE_ALIASES );
  1         2  
  1         83  
6 1     1   17 $VERSION = 1.05;
7             }
8              
9 1     1   2627 use Apache;
  0            
  0            
10             use Apache::Constants qw( OK );
11             use CGI qw();
12             use Apache::Cookie;
13             use constant CONFIG_COOKIE_INCLUDE => 'IncludeCookie';
14             use constant CONFIG_COOKIE_ALIAS => 'CookieAlias';
15             use constant CONFIG_ALIAS_SEP => ':';
16              
17             ########################################### main pod documentation begin ##
18              
19             =head1 NAME
20              
21             Apache::CookieToQuery - Rewrite query string by adding cookie information
22              
23             =head1 SYNOPSIS
24              
25             In httpd.conf or similiar
26            
27            
28             PerlAddVar IncludeCookie WSID
29             PerlAddVar IncludeCookie SID
30             PerlAddVar IncludeCookie QID
31             PerlAddVar CookieAlias WSID:WebSiteId
32             PerlAddVar CookieAlias QID:QueryId
33             PerlFixupHandler Apache::CookieToQuery
34            
35              
36             Requests for http://yourhost/YourLocation?extra_params=12345
37            
38             Will now become rewritten so they look similiar to:
39            
40             http://yourhost/YourLocation?WebSiteId=;SID=;QueryId=;extra_params=12345
41            
42             Where for example is the value of cookie named WSID
43              
44             =head1 DESCRIPTION
45              
46             This module will aid in adding cookie information to your query strings
47             so that cgi scripts or handlers underneath can have immidate benefit
48            
49             It requires mod_perl + Apache web server with PERL_FIXUP callback hook enabled
50             for more information on callback hooks refer to:
51             http://perl.apache.org/docs/1.0/guide/install.html#Callback_Hooks
52            
53             IncludeCookie specifies cookie names that will be added, if none are specified
54             any cookie name is taken into consideration
55            
56             CookieAlias specifies cookie name to look for and cookie name to alias it with
57             when query string is rewritten, if alias for a cookie name does not exist,
58             original cookie name will be used
59            
60             Please note that in the current implementation cookies always take precedence
61             over query string paramaters
62            
63             This package should always be installed as PerlFixupHandler so that it can execute before
64             standard PerlResponseHandler is called
65              
66             =head1 BUGS
67              
68             If you find any, please let the author know
69              
70             =head1 AUTHOR
71              
72             Alex Pavlovic
73             CPAN ID: ALEXP
74             alex.pavlovic@taskforce-1.com
75            
76              
77             =head1 COPYRIGHT
78              
79             Copyright (c) 2002 Alex Pavlovic. All rights reserved.
80             This program is free software; you can redistribute
81             it and/or modify it under the same terms as Perl itself.
82            
83             The full text of the license can be found in the
84             LICENSE file included with this module.
85              
86             =head1 SEE ALSO
87              
88             perl(1).
89              
90             =head1 PUBLIC METHODS
91              
92             Each public function/method is described here.
93             These are how you should interact with this module.
94              
95             =cut
96              
97             ############################################# main pod documentation end ##
98              
99             ################################################ subroutine header begin ##
100              
101             =head2 handler
102              
103             Usage : handler ( $apache )
104             Purpose : rewrites the query string of the original request
105             Returns : Server constant OK
106             Argument : apache instance
107              
108             =cut
109              
110             ################################################## subroutine header end ##
111              
112             sub handler {
113             my $apache = shift;
114             my $cgi = CGI->new ( { $apache->args } );
115             my $cookies = Apache::Cookie->new( $apache )->fetch;
116             %COOKIE_ALIASES = split CONFIG_ALIAS_SEP, join CONFIG_ALIAS_SEP, $apache->dir_config->get ( CONFIG_COOKIE_ALIAS ) unless %COOKIE_ALIASES;
117             @COOKIE_NAMES = $apache->dir_config->get ( CONFIG_COOKIE_INCLUDE ) unless @COOKIE_NAMES;
118             my $cookie_names = @COOKIE_NAMES ?
119             \@COOKIE_NAMES :
120             [ keys %$cookies ];
121             $cookies->{$_} and $cgi->param ( ( $COOKIE_ALIASES{$_} or $_ ), $cookies->{$_}->value ) for @$cookie_names;
122             $apache->args ( $cgi->query_string );
123             return OK;
124             }
125              
126             1;
127              
128             __END__