CGI-Plus
view release on metacpan or search on metacpan
use strict;
use Module::Build;
my ($build, $params);
$params = {
'dist_abstract' => 'CGI::Plus -- Extra utilities for CGI',
'dist_author' => 'Miko O\'Sullivan <miko@idocs.com>',
'module_name' => 'CGI::Plus',
'requires' => {
'CGI::Cookie' => 0,
'CGI::Safe' => 0,
'String::Util' => '1.24'
},
'dist_version_from' => 'lib/CGI/Plus.pm',
'license' => 'perl'
};
$build = Module::Build->new(%$params);
$build->create_build_script();
author:
- "Miko O'Sullivan <miko@idocs.com>"
generated_by: home grown
license: perl
name: CGI-Plus
provides:
CGI::Plus:
file: lib/CGI/Plus.pm
version: 0.15
requires:
CGI::Cookie: 0
CGI::Safe: 0
String::Util: 1.24
perl: 5.003
version: 0.15
Makefile.PL view on Meta::CPAN
# WriteMakefile params
$make_args = {
'NAME' => 'CGI::Plus',
'AUTHOR' => 'Miko O\'Sullivan <miko@idocs.com>',
'ABSTRACT' => 'CGI::Plus -- Extra utilities for CGI',
'PL_FILES' => {},
'EXE_FILES' => [],
'VERSION_FROM' => 'lib/CGI/Plus.pm',
'LICENSE' => 'perl',
'PREREQ_PM' => {
'CGI::Cookie' => 0,
'CGI::Safe' => 0,
'String::Util' => '1.24'
}
};
WriteMakefile(%$make_args);
$cgi->set_header('myheader', 'whatever');
# change content type
$cgi->set_content_type('text/json');
# output HTTP headers, including added cookies, the CSRF cookie,
# and the new header
print $cgi->header_plus;
# outputs something like this:
# Set-Cookie: newcookie=val2&2&val1&1; path=/
# Set-Cookie: mycookie=y&2&x&2; path=/
# Set-Cookie: csrf=v&KTFnGgpkZ4; path=/
# Date: Sun, 29 Jul 2012 04:08:06 GMT
# Myheader: whatever
# Content-Type: text/json; charset=ISO-8859-1
INSTALLATION
CGI::Plus can be installed with the usual routine:
perl Makefile.PL
make
lib/CGI/Plus.pm view on Meta::CPAN
package CGI::Plus;
use strict;
use Carp;
use CGI::Safe 'taint';
use base 'CGI::Safe';
use String::Util ':all';
use CGI::Cookie;
# version
our $VERSION = '0.15';
# Debug::ShowStuff
# use Debug::ShowStuff ':all';
# use Debug::ShowStuff::ShowVar;
# enable file uploads
$CGI::DISABLE_UPLOADS = 0;
lib/CGI/Plus.pm view on Meta::CPAN
$cgi->set_header('myheader', 'whatever');
# change content type
$cgi->set_content_type('text/json');
# output HTTP headers, including added cookies, the CSRF cookie,
# and the new header
print $cgi->header_plus;
# outputs something like this:
# Set-Cookie: newcookie=val2&2&val1&1; path=/
# Set-Cookie: mycookie=y&2&x&2; path=/
# Set-Cookie: csrf=v&KTFnGgpkZ4; path=/
# Date: Sun, 29 Jul 2012 04:08:06 GMT
# Myheader: whatever
# Content-Type: text/json; charset=ISO-8859-1
=head1 INSTALLATION
CGI::Plus can be installed with the usual routine:
perl Makefile.PL
make
lib/CGI/Plus.pm view on Meta::CPAN
sub initialize_cookies {
my ($cgi) = @_;
my ($got, %cookies);
# cookie hashes
$cgi->{'cookies'} = {};
$got = $cgi->{'cookies'}->{'incoming'} = {};
$cgi->{'cookies'}->{'outgoing'} = {};
# get hash of cookies that were sent
%cookies = CGI::Cookie->fetch();
# showhash \%cookies, title=>'%cookies';
# populate cookie values
foreach my $name (keys %cookies) {
my ($cookie, $element, @value);
$cookie = $cookies{$name};
$element = {};
# name of cookie
$element->{'name'} = $name;
lib/CGI/Plus.pm view on Meta::CPAN
$got = $cgi->ic->{$name} || {'name'=>$name};
# create cookie that gets sent back out
$send = {};
# clone $got cookie
foreach my $key (keys %$got) {
my $value = $got->{$key};
# original cookie
if (UNIVERSAL::isa $value, 'CGI::Cookie') {
$send->{$key} = $value;
}
# hashref
elsif (UNIVERSAL::isa $value, 'HASH') {
$send->{$key} = {%$value};
}
# else just copy
else {
lib/CGI/Plus.pm view on Meta::CPAN
# set expires: default to one year
if (exists $element{'expires'}) {
if (defined $element{'expires'})
{ $params{'-expires'} = $element{'expires'} }
}
else {
$params{'-expires'} = '+1y';
}
# create cookie object
$cookie = CGI::Cookie->new(%params);
if (! defined $cookie) {
# showhash \%params, title=>'error generating cookie';
die 'cookie error';
}
# add to cookie array
push @cookies, $cookie;
}
lib/CGI/Plus.pod view on Meta::CPAN
$cgi->set_header('myheader', 'whatever');
# change content type
$cgi->set_content_type('text/json');
# output HTTP headers, including added cookies, the CSRF cookie,
# and the new header
print $cgi->header_plus;
# outputs something like this:
# Set-Cookie: newcookie=val2&2&val1&1; path=/
# Set-Cookie: mycookie=y&2&x&2; path=/
# Set-Cookie: csrf=v&KTFnGgpkZ4; path=/
# Date: Sun, 29 Jul 2012 04:08:06 GMT
# Myheader: whatever
# Content-Type: text/json; charset=ISO-8859-1
=head1 INSTALLATION
CGI::Plus can be installed with the usual routine:
perl Makefile.PL
make
is_def "\$cookie->{'values'}", $cookie->{'values'}, "$name, $secondary_name: \$cookie->{'values'}";
# set new value for x
$cookie->{'values'}->{'x'} = 100;
# get headers
%headers = headers($cgi);
$secondary_name = 'cookies should include new_cookie';
FIND_COOKIE: {
foreach my $cookie (@{$headers{'Set-Cookie'}}) {
ok($cookie =~ m|^new_cookie=x&100;|s, "$name, $secondary_name: $cookie");
}
}
};
#
# new_send_cookie
#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
( run in 0.483 second using v1.01-cache-2.11-cpan-e9199f4ba4c )