ASP

 view release on metacpan or  search on metacpan

ASP.pm  view on Meta::CPAN


C<warn> (or more specifically, the __WARN__ signal) has been re-routed to
output to the browser.

FYI: When implemented, this tweak led to the removal of the prototypes
Matt placed on his subs.

=head2 Warn LIST

C<Warn> is an alias for the ASP::Print method described below. The
overloading of C<warn> as described above does not currently work
in Apache::ASP, so this is provided.

=cut
sub Warn { ASP::Print(@_); }

=head2 print LIST

C<print> is overloaded to write to the browser by default. The inherent
behavior of print has not been altered and you can still use an alternate
filehandle as you normally would. This allows you to use print just
as you would in CGI scripts. The following statement would need no
modification between CGI and ASP PerlScript:

    print param('URL'), " was requested by ", $ENV{REMOTE_HOST}, "\n";

=head2 Print LIST

Prints a string or comma separated list of strings to the browser. Use
as if you were using C<print> in a CGI application. Print gets around ASP's
limitations of 128k in a single $Response->Write() call.

NB: C<print> calls Print, so you could use either, but
print more closely resembles perl.

=cut
sub Print {
	for (@_) {
		if ( length($_) > 128000 ) {
			ASP::Print( unpack('a128000a*', $_) );
		} else {
			$main::Response->Write($_);
		}
	}
}

=head2 DebugPrint LIST

Output is displayed between HTML comments so the output doesn't
interfere with page aesthetics.

=cut
sub DebugPrint { ASP::Print("<!--\n", @_, "\n-->"); }

=head2 HTMLPrint LIST

The same as C<Print> except the output is HTML-encoded so that
any HTML tags appear as sent, i.e. E<lt> becomes &lt;, E<gt> becomes &gt; etc.

=cut
sub HTMLPrint { map { ASP::Print($main::Server->HTMLEncode($_)) } @_ ; }

=head2 die LIST

Prints the contents of LIST to the browser and then exits. die
automatically calls $Response->End for you, it also executes any
cleanup code you have added with C<AddDeathHook>.

=cut
sub die {
	ASP::Print(@_, "</BODY></HTML>");
	_END;
	$main::Response->End();
	CORE::die();
}

=head2 exit

Exits the current script. $Response->End is called automatically for you.
Any cleanup code added with C<AddDeathHook> is also called.

=cut
sub exit {
	_END;
	$main::Response->End();
	CORE::exit();
}

=head2 escape LIST

Escapes (URL-encodes) a list. Uses ASP object method
$Server->URLEncode().

=cut
sub escape { map { $main::Server->URLEncode($_) } @_; }

=head2 unescape LIST

Unescapes a URL-encoded list. Algorithms ripped from CGI.pm
method of the same name.

=cut
sub unescape {
	map {
		tr/+/ /;
		s/%([0-9a-fA-F]{2})/pack("c",hex($1))/ge;
	} @_;
}

=head2 escapeHTML LIST

Escapes a list of HTML. Uses ASP object method $Server->HTMLEncode().

If passed an array reference, escapeHTML will return a reference
to the escaped array.

=cut
sub escapeHTML {
	my ($flag, @args) = (0, @_);
	@args = @{$args[0]} and $flag++ if ref $args[0] eq "ARRAY"; 
	$_ = $main::Server->HTMLEncode($_) for @args;
	$flag ? \@args : @args;
}

=head2 unescapeHTML LIST

Unescapes an HTML-encoded list.

If passed an array reference, unescapeHTML will return a reference
to the un-escaped array.

=cut
sub unescapeHTML {
	my ($flag, @args) = (0, @_);
	@args = @{$args[0]} and $flag++ if ref $args[0] eq "ARRAY"; 
	map {
		s/&amp;/&/gi;
		s/&quot;/"/gi;
		s/&nbsp;/ /gi;
		s/&gt;/>/gi;
		s/&lt;/</gi;
		s/&#(\d+);/chr($1)/ge;
		s/&#x([0-9a-f]+);/chr(hex($1))/gi;
	} @args;
	$flag ? \@args : @args;
}

=head2 param EXPR [, EXPR]

Simplifies parameter access and makes switch from GET to POST transparent.

Given the following querystring:

	myscript.asp?x=a&x=b&y=c

    param()      returns ('x', 'y')
    param('y')   returns 'c'
    param('x')   returns ('a', 'b')
    param('x',1) returns 'a'
    param('x',2) returns 'b'

NOTE: Under Apache::ASP, param() simply passes the arguments
to CGI::param() because Apache::ASP doesn't support the $obj->{Count}
property used in this function.

=cut
sub param {
	if ($APACHE) {
		return (wantarray) ? (CGI::param(@_)) : scalar(CGI::param(@_));
	}
	unless (@_) {
		my @keys;
		push( @keys, $_ ) for ( Win32::OLE::in $main::Request->QueryString );
		push( @keys, $_ ) for ( Win32::OLE::in $main::Request->Form );
		return @keys;
	}
	$_[1] = 1 unless defined $_[1];
	unless (wantarray) {
		if ($main::Request->ServerVariables('REQUEST_METHOD')->Item eq 'GET') {
			return $main::Request->QueryString($_[0])->Item($_[1]);
		} else {
			return $main::Request->Form($_[0])->Item($_[1]);
		}
	} else {
		my ($i, @ret);
		if ($main::Request->ServerVariables('REQUEST_METHOD')->Item eq 'GET') {
			my $count = $main::Request->QueryString($_[0])->{Count};
			for ($i = 1; $i <= $count; $i++ ) {
				push @ret, $main::Request->QueryString($_[0])->Item($i);
			}
		} else {
			my $count = $main::Request->Form($_[0])->{Count};
			for ($i = 1; $i <= $count; $i++) {
				push @ret, $main::Request->Form($_[0])->Item($i);
			}
		}



( run in 2.836 seconds using v1.01-cache-2.11-cpan-140bd7fdf52 )