CGI-Thin

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

Revision history for Perl extension CGI::Thin.

0.52	Sat Sept 15 2001
	- New version for CPAN, but no changes from 0.5102

0.5102  Wed Jul 18  2001
	- Brought CGI::Thin and CGI::Thin::Cookies back into the same tarball for
	  easier distribution
	- Moved both test.pl files into the t directory as tests 01 and 02
	- Moved both *.pm files into the lib directory

0.51  April 2001
	- Create and spin off CGI::Thin::Cookies to parse and set cookies.
	  Thus this module can remain focused on form parsing only
	- Fixed some nits picked by Barrie Slaymaker <barries@slaysys.com>
		- switched from s/\+/ /g to tr/+/ / which should be a tad faster
		- You might want to use %([0-9a-fA-F]{2} to avoide grabbing illegal
		  escapes and passing non-hex data to hex().
		- switched from a pack("c",hex($1)) to a chr(hex($1))
		- ';' is a synonym for '&' in query strings, no longer overlooked.
		- What if there are parameters in both the query string and in
		  multipart/form-data? Could CGI::Thin be tweaked to process both?
		  Now it always looks at $ENV{QUERY_STRING} and then does multi-part or POST

MANIFEST  view on Meta::CPAN

Changes
Makefile.PL
MANIFEST
README
lib/CGI/Thin.pm
lib/CGI/Thin/Cookies.pm
t/01_init_thin.t
t/02_init_cookie.t

README  view on Meta::CPAN

        Under Apache::Registry, which emulates a CGI environmnet, it
        should be. Under plain ol' mod_perl, we need to interact
        with the Apache::Request class a bit instead of %ENV and
        STDIN.

        This feature may be added in the next incarnation of the
        module, or possibly a companion CGI::Thin::Mod_Perlish may
        be created to do it if the code will be too different.

SEE ALSO
    CGI::Thin::Cookies

SUPPORT
        Visit CGI::Thin's web site at
            http://www.PlatypiVentures.com/perl/modules/cgi_thin.shtml
        Send email to
            mailto:cgi_thin@PlatypiVentures.com

AUTHOR
        R. Geoffrey Avery
        CPAN ID: RGEOFFREY

lib/CGI/Thin.pm  view on Meta::CPAN

Under plain ol' mod_perl, we need to interact with the
Apache::Request class a bit instead of %ENV and STDIN.

This feature may be added in the next incarnation of the module, or possibly a companion
CGI::Thin::Mod_Perlish may be created to do it if the code will be too different.

=back

=head1 SEE ALSO

CGI::Thin::Cookies

=head1 SUPPORT

    Visit CGI::Thin's web site at
        http://www.PlatypiVentures.com/perl/modules/cgi_thin.shtml
    Send email to
        mailto:cgi_thin@PlatypiVentures.com

=head1 AUTHOR

lib/CGI/Thin/Cookies.pm  view on Meta::CPAN

#!/usr/local/bin/perl

package CGI::Thin::Cookies;
use strict;

BEGIN {
	use Exporter ();
	use vars qw ($VERSION @ISA @EXPORT);
	$VERSION = 0.52;
	@ISA		= qw (Exporter);
	@EXPORT		= qw (&Parse_Cookies &Set_Cookie);
}

########################################### main pod documentation begin ##

=pod

=head1 NAME

CGI::Thin::Cookies - A very lightweight way to read and set Cookies

=head1 SYNOPSIS

C<use CGI::Thin::Cookies;>

C<my %cookie = &Parse_Cookies ();>

C<print &Set_Cookie (VALUE => 'a cookie value', EXPIRE => '+12h);>

=head1 DESCRIPTION

This module is a very lightweight parser and setter of cookies.  And
it has a special feature that it will return an array if the same key
is used twice for different cookies with the ame name.  And you can
force an array to avoid complications.

=head1 USAGE

    * 'CGI::Thin::Cookies::Parse_Cookies(@keys)'
        The optional @keys will be used to force arrays to be returned.

		The function returns a hash of the cookies available to the script. It
		can return more than one cookie if they exist.

    * 'CGI::Thin::Cookies::Set_Cookie (%options)VALUE => 'a cookie value', EXPIRE => '+12h);'

		The %options contain the the following information for the cookie:

		NAME: the name of the cookie
		VALUE: a string with the value of the cookie
		DOMAIN: the domain for the cookie, default is the '.secondaryDomain.toplevelDomain'
		PATH: the path within the domain, default is '/'
		SECURE: true or false value for setting the SECURE flag
		EXPIRE: when to expire including the following options

lib/CGI/Thin/Cookies.pm  view on Meta::CPAN

=over 4

=back

=head1 SEE ALSO

CGI::Thin

=head1 SUPPORT

    Visit CGI::Thin::Cookies' web site at
        http://www.PlatypiVentures.com/perl/modules/cgi_thin.shtml
    Send email to
        mailto:cgi_thin@PlatypiVentures.com

=head1 AUTHOR

    R. Geoffrey Avery
    CPAN ID: RGEOFFREY
    modules@PlatypiVentures.com
    http://www.PlatypiVentures.com/perl

lib/CGI/Thin/Cookies.pm  view on Meta::CPAN


This module is free software, you may redistribute it or modify in under the same terms as Perl itself.

=cut

############################################# main pod documentation end ##

################################################ subroutine header begin ##
################################################## subroutine header end ##

sub Parse_Cookies
{
	my (%cookie);
	foreach (split(/; /, $ENV{'HTTP_COOKIE'})) {
		tr/+/ /;
		my ($chip, $val) = split(/=/, $_, 2);
		$chip =~ s/%([A-Fa-f0-9]{2})/chr(hex($1))/ge;
		$val  =~ s/%([A-Fa-f0-9]{2})/chr(hex($1))/ge;

		if ( defined($cookie{$chip})) {
			$cookie{$chip} = [$cookie{$chip}] unless (ref ($cookie{$chip}) eq "ARRAY");

lib/CGI/Thin/Cookies.pm  view on Meta::CPAN

	foreach (@_) {
		$cookie{$_} = &Force_Array ($cookie{$_}) if ($cookie{$_});
	}

	return (%cookie);
}

################################################ subroutine header begin ##
################################################## subroutine header end ##

sub Set_Cookie
{
	my (%cookie) = @_;

	$cookie{'VALUE'} =~ s/ /+/g;
	$cookie{'VALUE'} = 'deleted' if ($cookie{'EXPIRE'} eq 'delete');

	$cookie{'EXPIRE'} = &Expire ($cookie{'EXPIRE'});

	$cookie{'PATH'}	= '/' unless $cookie{'PATH'};

	unless ($cookie{'DOMAIN'}) {
		my @where = split ('\.', $ENV{'SERVER_NAME'});
		$cookie{'DOMAIN'} = '.' . join ('.', splice (@where, -2));
	}

	return (join ('; ',
				  "Set-Cookie: $cookie{'NAME'}\=$cookie{'VALUE'}",
				  $cookie{'EXPIRE'},
				  "path\=$cookie{'PATH'}",
				  "domain\=$cookie{'DOMAIN'}",
				  (($cookie{'SECURE'}) ? 'secure' : '')
				 ) . "\n");
}

################################################ subroutine header begin ##
# Loosely based on &expire_calc from CGI.pm
################################################### subroutine header end ##

t/02_init_cookie.t  view on Meta::CPAN

# 02_init_cookie.t; just to load CGI::Thin::Cookies by using it

$|++; 
print "1..1\n";
my($test) = 1;

use CGI::Thin::Cookies;
$loaded = 1;
$loaded ? print "ok $test\n" : print "not ok $test\n";
$test++;

# end of 02_init_cookie.t



( run in 0.412 second using v1.01-cache-2.11-cpan-e9199f4ba4c )