Add entries_cache_meta and recententries to MANIFEST.medium.
[blosxom-plugins.git] / general / cookies
blobea755367ac2e3bb117297320e39e6561ca284733
1 # Blosxom Plugin: cookies
2 # Author(s): Rael Dornfest <rael@oreilly.com> 
3 # Version: 2003-03-20
4 # Documentation: See the bottom of this file or type: perldoc cookies
6 package cookies;
8 # --- Configurable variables -----
10 # What domain should I assign to cookies (e.g. .example.com, www.example.com)?
11 # REQUIRED; if you don't fill in a domain, the plug-in won't work properly.
12 $domain = '';
14 # What path should I assign to cookies?
15 $path = '/';
17 # How soon should cookies expire?
18 # (e.g. +1d is 1 day, +3m is 3 months, and +10y is 10 years from now)
19 # Leave this blank and the cookie will expire when the browser is closed
20 $expires = '+10y';
22 # --------------------------------
24 use CGI qw/:standard/;
26 my %cookies = ();
28 sub start {
29   foreach ( cookie() ) {
30     my %hash = cookie($_);
31     $cookies{$_} = \%hash;
32   }
33   1;
36 sub foot {
37   my @cookies = values %cookies;
38   $blosxom::header->{'-cookie'} = \@cookies;
40   1;
43 sub add {
44   foreach ( @_ ) {
45     my($name) = $_ =~ /^(.+?)=/;
46     $cookies{$name} = $_;
47   }
48   1;
51 sub remove {
52   foreach ( @_ ) {
53     delete $cookies{$_};
54   }
55   1;
58 sub clear {
59   foreach ( @_ ) {
60     $cookies{$_} = '';
61   }
62   1;
65 sub get {
66   my($name) = @_;
67   return $name ? $cookies{$name} : \%cookies;
70 sub list {
71   return keys %cookies;
77 __END__
79 =head1 NAME
81 Blosxom Plug-in: cookies
83 =head1 SYNOPSIS
85 Provides basic cookie functionality for use by any number of Blosxom plug-ins.
87 =head1 INSTALLATION & CONFIGURATION
89 Drop the cookies plug-in into your Blosxom plugins directory. 
91 Be sure cookies is called last, giving all other plugins a chance to 
92 add, remove, and clear cookies before the the cookies plug-in returns the
93 header to the browser.  The easiest way to do this is to rename the plug-in
94 9999cookies or the like, assuring that is sorted last, alphanumerically.
96 Set a $domain for your cookies.  I recommend using any host in your domain, 
97 e.g. .example.com, instead of just limiting to www, e.g. www.yourdomain.
99 Assign a $path for your cookies.  This should be the base path of your weblog.
100 Use / if your weblog lives at the root of your domain (e.g. http://www.example.com/) or /weblog, for example, if it lives at a /weblog subpath (e.g. http://www.example.com/weblog).
102 Set a time-out period for cookies.  While there are various allowed forms 
103 for this expires piece (see perldoc CGI.pm), I like using +n(d,m,y) for
104 n days, months, or years from now.  For example: +1d is 1 day, 
105 +3m is 3 months, and +10y is 10 years from now.  The default is 10 years
106 from now.
108 =head1 USAGE
110 As an end-user, once you have the cookies plug-in installed and configured, 
111 you're done.
113 =head1 DEVELOPMENT
115 Plug-in developers may use the cookies module as a base for cookie-usage
116 by your own Blosxom plug-in.  An example may be found in the writeback 
117 plug-in's use of cookies to remember the name and url of a person leaving a 
118 comment.
120 All cookies are kept on a stack (in a %cookies hash, actually).  Incoming
121 cookies sent by the browser are automagically added to the %cookies stack
122 in the start() subroutine.
124 You have the following methods at your disposal:
126 =item * add($cookie1, $cookie2, ...) adds a cookie to the stack to be sent to the client browser.  Cookies should be well-formed; I suggest using the Perl CGI.pm module's cookie() subroutine to create each cookie.
128 So that cookies can all be handled in the same manner by the cookies plug-in, 
129 you must use a hash as your cookie value, even if you only have one value to
130 set.
132 usage:
134 &cookies::add(
135   cookie(
136     -name=>'plugin cookie 1'
137     -value=>{ 'some key' => 'some value' }
138     -path=>$cookies::path,
139     -domain=>$cookies::domain
140   )
141   cookie(
142     -name=>'plugin cookie 2', 
143     -value=>{ 'first key' => 'first value', 'second key' => 'second value' }
144     -path=>$cookies::path,
145     -domain=>$cookies::domain
146   )
149 =item * remove('cookie name') removes a previously added cookie named 'cookie 
150 name' from the stack.  Note, this does not unset the cookie in the client 
151 browser.
153 usage:
155 &cookies::remove('plugin cookie 1');
157 =item * clear('cookie name') sets a blank value for the 'cookie name' cookie,
158 thereby clearing it in the client browser.
160 usage:
162 &cookies::clear('plugin cookie 2');
164 =item * list() lists the names of all cookies on the stack.
166 usage:
168 my @cookie_names = &cookies::list();
170 =item * get() gets a reference to a hash {cookie name => cookie value} of all 
171 cookies on the stack.  get('cookie name') gets a hash reference for the 'cookie name' cookie.
173 usage:
175 my $cookies = &cookies::get();
176 my @cookie_names = keys %$cookies;
178 my $particular_cookie = &cookies::get('cookie name');
179 my $values = values %$particular_cookie;
181 =head1 VERSION
183 2003-03-20
185 =head1 AUTHOR
187 Rael Dornfest  <rael@oreilly.com>, http://www.raelity.org/
189 This plugin is now maintained by the Blosxom Sourceforge Team,
190 <blosxom-devel@lists.sourceforge.net>.
192 =head1 SEE ALSO
194 Blosxom Home/Docs/Licensing: http://blosxom.sourceforge.net/
196 Blosxom Plugin Docs: http://blosxom.sourceforge.net/documentation/users/plugins.html
198 =head1 BUGS
200 None known; please send bug reports and feedback to the Blosxom
201 development mailing list <blosxom-devel@lists.sourceforge.net>.
203 =head1 LICENSE
205 Blosxom and this Blosxom Plug-in
206 Copyright 2003, Rael Dornfest 
208 Permission is hereby granted, free of charge, to any person obtaining a
209 copy of this software and associated documentation files (the "Software"),
210 to deal in the Software without restriction, including without limitation
211 the rights to use, copy, modify, merge, publish, distribute, sublicense,
212 and/or sell copies of the Software, and to permit persons to whom the
213 Software is furnished to do so, subject to the following conditions:
215 The above copyright notice and this permission notice shall be included
216 in all copies or substantial portions of the Software.
218 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
219 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
220 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
221 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
222 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
223 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
224 OTHER DEALINGS IN THE SOFTWARE.