AxKit-XSP-Cookie
view release on metacpan or search on metacpan
Revision history for Perl extension AxKit::XSP::Cookie.
1.41
- Doug Wilson <dougw@cpan.org> found a bug which Robin Berjon <robin@knowscape.com>
fixed. In fact, the previous item in the log never happened, only the version
number was changed :)
1.4
- Updated to AxKit 1.4's API
1.00 Wed Mar 28 08:33:48 2001
package AxKit::XSP::Cookie;
use strict;
use Apache::AxKit::Language::XSP;
use Apache::Cookie;
use vars qw/@ISA $NS $VERSION/;
@ISA = ('Apache::AxKit::Language::XSP');
$NS = 'http://axkit.org/NS/xsp/cookie/v1';
$VERSION = "1.41";
## Taglib subs
my $cookie_context = '';
## Parser subs
sub parse_start {
my ($e, $tag, %attribs) = @_;
#warn "Checking: $tag\n";
if ($tag eq 'create') {
$cookie_context = 'create';
my $code = '{ my $__cookie = Apache::Cookie->new($r);';
if ($attribs{name}) {
$code .= '$__cookie->name(q|' . $attribs{name} . '|);';
}
if ($attribs{value}) {
$code .= '$__cookie->value(q|' . $attribs{value} . '|);';
}
if ($attribs{domain}) {
$code .= '$__cookie->domain(q|' . $attribs{domain} . '|);';
}
elsif ($tag eq 'path') {
return '$__cookie->path(""';
}
elsif ($tag eq 'secure') {
return '$__cookie->secure(""';
}
elsif ($tag eq 'fetch') {
$cookie_context = 'fetch';
$e->start_expr($tag);
my $code = 'my (%__cookies, $__cookie, $__cookie_name);' . "\n";
$code .= '%__cookies = Apache::Cookie->fetch;';
$code .= '$__cookie_name = ""';
if ($attribs{name}) {
$code .= '. q|' . $attribs{name} . '|;';
$code .= '$__cookie = $__cookies{$__cookie_name} || Apache::Cookie->new($r);';
}
return $code;
}
else {
die "Unknown cookie tag: $tag";
}
}
sub parse_char {
if ($tag eq 'create') {
$cookie_context = '';
return '$__cookie->bake;}' . "\n";
}
elsif ($tag eq 'name') {
if ($cookie_context eq 'create') {
return ');';
}
else {
return ';$__cookie = $__cookies{$__cookie_name} || Apache::Cookie->new($r);';
}
}
elsif ($tag eq 'value') {
if ($cookie_context eq 'create') {
return ');';
}
}
elsif ($tag eq 'expires') {
if ($cookie_context eq 'create') {
sub parse_final {
# compat only
}
1;
__END__
=head1 NAME
AxKit::XSP::Cookie - An XSP library for setting and getting HTTP cookies.
=head1 SYNOPSIS
Add the taglib to AxKit (via httpd.conf or .htaccess):
AxAddXSPTaglib AxKit::XSP::Cookie
Add the cookie: namespace to your XSP C<<xsp:page>> tag:
<xsp:page
language="Perl"
xmlns:xsp="http://apache.org/xsp/core/v1"
xmlns:cookie="http://axkit.org/NS/xsp/cookie/v1"
>
Then, put the taglib to work:
Set a cookie:
<cookie:create name="newCookie" value="somevalue" />
Get the value for a previous cookie:
<cookie:fetch name="oldCookie" />
=head1 DESCRIPTION
The XSP cookie: tag library implements a simple way to set/get HTTP cookies.
=head1 TAG REFERENCE
In order to provide maximum flexibility for XSP developers, the cookie: taglib allows all of its arguments to be passed either
as attributes of the two 'wrapper' elements (C<<cookie:create>> and C<<cookie:fetch>>), or as child elements of the same.
Allowed only as the child of a C<<cookie:create>> element, this tag defines the value for the cookie.
=head2 C<<cookie:path>>
Allowed only as the child of a C<<cookie:create>> element, this tag defines the 'path' field for the cookie.
=head2 C<<cookie:expires>>
Allowed only as the child of a C<<cookie:create>> element, this tag sets the cookie's expiry date. It accepts the same types
values that Apache::Cookie does.
=head2 C<<cookie:domain>>
Allowed only as the child of a C<<cookie:create>> element, this tag defines the 'domain' field for the cookie.
=head2 C<<cookie:secure>>
Accepting only the values of O or 1, this tag sets or unsets the cookie's 'secure' flag. It is allowed only as the child
of a C<<cookie:create>> element.
Kip Hampton, khampton@totalcinema.com
=head1 COPYRIGHT
Copyright (c) 2001 Kip Hampton. All rights reserved. This program is
free software; you can redistribute it and/or modify it under the same
terms as Perl itself.
=head1 SEE ALSO
AxKit, Apache::Cookie, CGI::Cookie
=cut
Changes
Cookie.pm
Makefile.PL
MANIFEST
t/01basic.t
README
Makefile.PL view on Meta::CPAN
use ExtUtils::MakeMaker;
# See lib/ExtUtils/MakeMaker.pm for details of how to influence
# the contents of the Makefile that is written.
WriteMakefile(
'NAME' => 'AxKit::XSP::Cookie',
'VERSION_FROM' => 'Cookie.pm', # finds $VERSION
'PREREQ_PM' => {
'Apache::Cookie' => 0,
'AxKit' => 1.4,
},
);
AxKit::XSP::Cookie - An XSP library for setting and getting HTTP cookies.
Add the taglib to AxKit (via httpd.conf or .htaccess):
AxAddXSPTaglib AxKit::XSP::Cookie
Add the cookie: namespace to your XSP <xsp:page> tag:
<xsp:page
language="Perl"
xmlns:xsp="http://apache.org/xsp/core/v1"
xmlns:cookie="http://axkit.org/NS/xsp/cookie/v1"
>
Then, put the taglib to work:
Set a cookie:
<cookie:create name="newCookie" value="somevalue" />
Get the value for a previous cookie:
<cookie:fetch name="oldCookie" />
Fetch the value for a previous cookie whose name argument
is hard-coded into the script:
<cookie:fetch name="chocolateChip"/>
Fetch the value for a previous cookie whose name is
determined at run-time:
<cookie:fetch>
t/01basic.t view on Meta::CPAN
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl test.pl'
######################### We start with some black magic to print on failure.
# Change 1..1 below to 1..last_test_to_print .
# (It may become useful if the test is moved to ./t subdirectory.)
BEGIN { $| = 1; print "1..1\n"; }
END {print "not ok 1\n" unless $loaded;}
use AxKit::XSP::Cookie;
$loaded = 1;
print "ok 1\n";
######################### End of black magic.
# Insert your test code below (better if it prints "ok 13"
# (correspondingly "not ok 13") depending on the success of chunk 13
# of the test code):
( run in 1.357 second using v1.01-cache-2.11-cpan-e9199f4ba4c )