CGI-Info
view release on metacpan or search on metacpan
# Code to display a different web page for a browser, search engine and
# smartphone
use Template;
use CGI::Info;
my $info = CGI::Info->new();
my $dir = $info->rootdir() . '/templates/' . $info->browser_type();
my $filename = ref($self);
$filename =~ s/::/\//g;
$filename = "$dir/$filename.tmpl";
if((!-f $filename) || (!-r $filename)) {
die "Can't open $filename";
}
my $template = Template->new();
$template->process($filename, {}) || die $template->error();
## get\_cookie
Returns a cookie's value, or undef if no name is given, or the requested
cookie isn't in the jar.
Deprecated - use cookie() instead.
use CGI::Info;
my $i = CGI::Info->new();
my $name = $i->get_cookie(cookie_name => 'name');
print "Your name is $name\n";
my $address = $i->get_cookie('address');
print "Your address is $address\n";
## cookie
Returns a cookie's value, or undef if no name is given, or the requested
cookie isn't in the jar.
API is the same as "param",
it will replace the "get\_cookie" method in the future.
use CGI::Info;
my $name = CGI::Info->new()->cookie('name');
print "Your name is $name\n";
### API SPECIFICATION
#### INPUT
{
cookie_name => {
'type' => 'string',
'min' => 1,
'matches' => qr/^[!#-'*+\-.\^_`|~0-9A-Za-z]+$/ # RFC6265
}
}
#### OUTPUT
Cookie not set: `undef`
Cookie set:
{
type => 'string',
optional => 1,
matches => qr/ # RFC6265
^
(?:
"[\x21\x23-\x2B\x2D-\x3A\x3C-\x5B\x5D-\x7E]*" # quoted
| [\x21\x23-\x2B\x2D-\x3A\x3C-\x5B\x5D-\x7E]* # unquoted
)
$
/x
}
## status($status)
Sets or returns the status of the object,
200 for OK,
otherwise an HTTP error code
- $status
Optional integer value to be set or retrieved.
If omitted, the value is retrieved.
## messages
Returns the messages that the object has generated as a ref to an array of hashes.
my @messages;
if(my $w = $info->messages()) {
@messages = map { $_->{'message'} } @{$w};
} else {
@messages = ();
}
print STDERR join(';', @messages), "\n";
## messages\_as\_string
Returns the messages of that the object has generated as a string.
## cache($cache)
Get/set the internal cache system.
Use this rather than pass the cache argument to `new()` if you see these error messages,
"(in cleanup) Failed to get MD5\_CTX pointer".
It's some obscure problem that I can't work out,
but calling this after `new()` works.
- $cache
Optional cache object.
When not given,
returns the current cache object.
## set\_logger
Sets the class, array, code reference, or file that will be used for logging.
( run in 0.569 second using v1.01-cache-2.11-cpan-39bf76dae61 )