Apache-ASP
view release on metacpan or search on metacpan
lib/Apache/ASP/Server.pm view on Meta::CPAN
local *0 = \$file_final;
$self->{asp}{Response}->Include($file, @_);
$self->{asp}{Response}->End;
}
# shamelessly ripped off from CGI.pm, by Lincoln D. Stein.
sub URLEncode {
my $toencode = $_[1];
$toencode =~ s/([^a-zA-Z0-9_\-.])/uc sprintf("%%%02x",ord($1))/esg;
$toencode;
}
sub HTMLDecode {
my($self, $decode) = @_;
$decode=~s/>/>/sg;
$decode=~s/</</sg;
$decode=~s/'/'/sg;
$decode=~s/"/\"/sg;
$decode=~s/&/\&/sg;
$decode;
}
sub HTMLEncode {
my($self, $toencode) = @_;
return '' unless defined $toencode;
my $data_ref;
if(ref $toencode) {
$data_ref = $toencode;
} else {
$data_ref = \$toencode;
}
$$data_ref =~ s/&/&/sg;
$$data_ref =~ s/\"/"/sg;
$$data_ref =~ s/\'/'/sg;
$$data_ref =~ s/>/>/sg;
$$data_ref =~ s/</</sg;
ref($toencode) ? $data_ref : $$data_ref;
}
sub HTMLEncodeByValue {
my($self, $toencode) = @_;
return '' unless defined $toencode;
$toencode =~ s/&/&/sg;
$toencode =~ s/\"/"/sg;
$toencode =~ s/\'/'/sg;
$toencode =~ s/>/>/sg;
$toencode =~ s/</</sg;
return $toencode;
}
sub RegisterCleanup {
my($self, $code) = @_;
if(ref($code) =~ /^CODE/) {
$self->{asp}{dbg} && $self->{asp}->Debug("RegisterCleanup() called", caller());
push(@{$self->{asp}{cleanup}}, $code);
} else {
$self->{asp}->Error("$code need to be a perl sub reference, see README");
}
}
sub MapInclude {
my($self, $file) = @_;
$self->{asp}->SearchDirs($file);
}
sub MapPath {
my($self, $path) = @_;
my $subr = $self->{asp}{r}->lookup_uri($path);
$subr ? $subr->filename : undef;
}
*SendMail = *Mail;
sub Mail {
shift->{asp}->SendMail(@_);
}
sub URL {
my($self, $url, $params) = @_;
$params ||= {};
if($url =~ s/\?(.*)$//is) {
my $old_params = $self->{asp}{Request}->ParseParams($1);
$old_params ||= {};
$params = { %$old_params, %$params };
}
my $asp = $self->{asp};
if($asp->{session_url} && $asp->{session_id} && ! $asp->{session_cookie}) {
my $match = $asp->{session_url_match};
if(
# if we have match expression, try it
($match && $url =~ /$match/)
# then if server path, check matches cookie space
|| ($url =~ m|^/| and $url =~ m|^$asp->{cookie_path}|)
# then do all local paths, matching NOT some URI PROTO
|| ($url !~ m|^[^\?\/]+?:|)
)
{
# this should overwrite an incorrectly passed in data
$params->{$Apache::ASP::SessionCookieName} = $asp->{session_id};
}
}
my($k,$v, @query);
# changed to use sort so this function outputs the same URL every time
for my $k ( sort keys %$params ) {
my $v = $params->{$k};
# inline the URLEncode function for speed
$k =~ s/([^a-zA-Z0-9_\-.])/uc sprintf("%%%02x",ord($1))/egs;
my @values = (ref($v) and ref($v) eq 'ARRAY') ? @$v : ($v);
for my $value ( @values ) {
$value =~ s/([^a-zA-Z0-9_\-.])/uc sprintf("%%%02x",ord($1))/egs;
push(@query, $k.'='.$value);
( run in 1.995 second using v1.01-cache-2.11-cpan-437f7b0c052 )