perl_mlb
view release on metacpan or search on metacpan
END_OF_FUNC
#### Method: content_type
# Returns the content_type string
####
'content_type' => <<'END_OF_FUNC',
sub content_type {
return $ENV{'CONTENT_TYPE'};
}
END_OF_FUNC
#### Method: path_translated
# Return the physical path information provided
# by the URL (if any)
####
'path_translated' => <<'END_OF_FUNC',
sub path_translated {
return $ENV{'PATH_TRANSLATED'};
}
END_OF_FUNC
#### Method: query_string
# Synthesize a query string from our current
# parameters
####
'query_string' => <<'END_OF_FUNC',
sub query_string {
my($self) = self_or_default(@_);
my($param,$value,@pairs);
foreach $param ($self->param) {
my($eparam) = escape($param);
foreach $value ($self->param($param)) {
$value = escape($value);
next unless defined $value;
push(@pairs,"$eparam=$value");
}
}
foreach (keys %{$self->{'.fieldnames'}}) {
push(@pairs,".cgifields=".escape("$_"));
}
return join($USE_PARAM_SEMICOLONS ? ';' : '&',@pairs);
}
END_OF_FUNC
#### Method: accept
# Without parameters, returns an array of the
# MIME types the browser accepts.
# With a single parameter equal to a MIME
# type, will return undef if the browser won't
# accept it, 1 if the browser accepts it but
# doesn't give a preference, or a floating point
# value between 0.0 and 1.0 if the browser
# declares a quantitative score for it.
# This handles MIME type globs correctly.
####
'Accept' => <<'END_OF_FUNC',
sub Accept {
my($self,$search) = self_or_CGI(@_);
my(%prefs,$type,$pref,$pat);
my(@accept) = split(',',$self->http('accept'));
foreach (@accept) {
($pref) = /q=(\d\.\d+|\d+)/;
($type) = m#(\S+/[^;]+)#;
next unless $type;
$prefs{$type}=$pref || 1;
}
return keys %prefs unless $search;
# if a search type is provided, we may need to
# perform a pattern matching operation.
# The MIME types use a glob mechanism, which
# is easily translated into a perl pattern match
# First return the preference for directly supported
# types:
return $prefs{$search} if $prefs{$search};
# Didn't get it, so try pattern matching.
foreach (keys %prefs) {
next unless /\*/; # not a pattern match
($pat = $_) =~ s/([^\w*])/\\$1/g; # escape meta characters
$pat =~ s/\*/.*/g; # turn it into a pattern
return $prefs{$_} if $search=~/$pat/;
}
}
END_OF_FUNC
#### Method: user_agent
# If called with no parameters, returns the user agent.
# If called with one parameter, does a pattern match (case
# insensitive) on the user agent.
####
'user_agent' => <<'END_OF_FUNC',
sub user_agent {
my($self,$match)=self_or_CGI(@_);
return $self->http('user_agent') unless $match;
return $self->http('user_agent') =~ /$match/i;
}
END_OF_FUNC
#### Method: raw_cookie
# Returns the magic cookies for the session.
# The cookies are not parsed or altered in any way, i.e.
# cookies are returned exactly as given in the HTTP
# headers. If a cookie name is given, only that cookie's
# value is returned, otherwise the entire raw cookie
# is returned.
####
'raw_cookie' => <<'END_OF_FUNC',
sub raw_cookie {
my($self,$key) = self_or_CGI(@_);
require CGI::Cookie;
if (defined($key)) {
$self->{'.raw_cookies'} = CGI::Cookie->raw_fetch
unless $self->{'.raw_cookies'};
return () unless $self->{'.raw_cookies'};
return () unless $self->{'.raw_cookies'}->{$key};
return $self->{'.raw_cookies'}->{$key};
}
return $self->http('cookie') || $ENV{'COOKIE'} || '';
}
END_OF_FUNC
#### Method: virtual_host
# Return the name of the virtual_host, which
# is not always the same as the server
######
'virtual_host' => <<'END_OF_FUNC',
sub virtual_host {
my $vh = http('host') || server_name();
$vh =~ s/:\d+$//; # get rid of port number
return $vh;
}
END_OF_FUNC
#### Method: remote_host
# Return the name of the remote host, or its IP
# address if unavailable. If this variable isn't
( run in 1.607 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )